Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: insert data through gui application (JFrame)

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default insert data through gui application (JFrame)

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;

    class InsertData extends Frame implements ActionListener

    {
    JLabel sno,sname,sadd;
    JTextField tno,tname,tadd;
    JButton Insert;
    Connection con;
    PreparedStatement ps;
    ResultSet rs;

    InsertData()

    {
    setLayout(new FlowLayout());
    setSize(200,200);
    sno=new JLabel("student number");
    sname=new JLabel("student name");
    sadd=new JLabel("student address");
    tno=new JTextField(15);
    tname=new JTextField(15);
    tadd=new JTextField(15);
    Insert=new JButton("Insert");

    sno. add(sno);
    tno.add(tno);
    sname.add(sname);
    tname.add(tname);
    sadd.add(sadd);
    tadd.add(tadd);
    Insert.add(Insert);
    Insert.addActionListener(this);
    //create jdbc connection
    try
    {



    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521rcl","scott","tiger");
    //make sql query as pre.compiled sql query
    PreparedStatement ps=con.prepareStatement("insert into student values(?,?,?)");

    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    public void actionPerformed(ActionEvent ae)
    {
    try
    {
    String sno=tno.getText();
    String sname=tname.getText();
    String sadd=tadd.getText();
    ps.setString(1,sno);
    ps.setString(2,sname);
    ps.setString(3,sadd);
    ps.executeQuery();



    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    rs.close();
    ps.close();
    con.close();

    }
    }
    class InsertDemo
    {
    public static void main(String args[]) throws Exception
    {
    InsertData io=new InsertData();
    io.setVisible(true);

    }
    }
    compile time error
    unreported exception at rs.close(),ps.close(),con.close() ;;;;;


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: insert data through gui application (JFrame)

    compile time error
    Please copy the full text of the compiler's error message and post it here.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: January 24th, 2013, 11:55 AM
  2. Replies: 1
    Last Post: April 9th, 2012, 05:13 PM
  3. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  4. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  5. [B]Insert a JFrame and a JTable in a JSplitPane[/B]
    By sincerelibran in forum AWT / Java Swing
    Replies: 1
    Last Post: January 23rd, 2011, 01:59 PM