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() ;;;;;