I'm trying to insert data into my sqlite db. I'm using eclipse mars and java se 1.7 Here's my code public void actionPerformed(ActionEvent arg0) { String query1 = "select Name from Members where Id_no=?"; String query = "insert into RequestedBooks (Book Title,Requested By,Author,Subject) values (?, ?, ?, ?)"; PreparedStatement pst,pst1; try { pst1 = con.prepareStatement(query1); pst1.setString(1, l.id); ResultSet rs = pst1.executeQuery(); String id = null; while(rs.next()){ id = rs.getString(1); } pst1.close(); pst=con.prepareStatement(query); pst.setString(1, textField.getText()); pst.setString(2, id); pst.setString(3, textField_1.getText()); pst.setString(4, textField_2.getText()); pst.execute();
JOptionPane.showMessageDialog(null, "Request Added");
pst.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Aucun commentaire:
Enregistrer un commentaire