i am trying to make Java ucanaccess program and for some reasons i am not able to insert record to database and have appeared some error messages as following:
package lcp_v1;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.*;
public class DB2 extends JFrame implements ActionListener {
private JPanel contentPane;
private JTextField id_tt;
private JTextField name_tt;
Connection con;
Statement st;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DB2 frame = new DB2();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public DB2() {
try {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 577, 550);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblEmployeeId = new JLabel("employee id");
lblEmployeeId.setBounds(39, 53, 123, 23);
contentPane.add(lblEmployeeId);
id_tt = new JTextField("");
id_tt.setBounds(161, 50, 136, 29);
contentPane.add(id_tt);
id_tt.setColumns(10);
JLabel lblName = new JLabel("Name");
lblName.setBounds(39, 118, 71, 23);
contentPane.add(lblName);
name_tt = new JTextField("");
name_tt.setColumns(10);
name_tt.setBounds(161, 115, 136, 29);
contentPane.add(name_tt);
JButton insert = new JButton("Insert");
insert.setBounds(39, 388, 105, 30);
contentPane.add(insert);
insert.addActionListener(this);
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String dataSource = "jdbc:ucanaccess://D:/Database.accdb";
con = DriverManager.getConnection(dataSource, "", "");
Statement st = con.createStatement();
} catch (Exception e) {
}
}//end DB2 constructor
public void actionPerformed(ActionEvent ae) {
try {
String id = id_tt.getText();
String name = name_tt.getText();
String s1 = "INSERT INTO Table1 (ID, Name) VALUES (id,name)";
st.executeUpdate(s1);
id_tt.setText("");
name_tt.setText("");
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
please tell me what error did i make.thanks a lot