1. I am not sure about the correct codes to use in saving (Int value) items from jcomboBox to my database Table,
2. I am also not sure if am to include the Foreign Column when writing my SQL statement to insert value into the Database table that has Foreign Key column
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.01:3306/CMS", "root", "2bforever");
quary = "INSERT INTO anniversary VALUES (?,?,?,?,?)";
ps = con.prepareStatement(quary);
ps.setString(1, jTextField1.getText());
ps.setString(2, jTextField2.getText());
ps.setString(3, (String) jComboBox1.getSelectedItem());
ps.setString(4, (String) jComboBox2.getSelectedItem());
ps.setString(5, jTextField3.getText());
int result =ps.executeUpdate();
con.close();
jLabel6.setText("Record successfully Saved.");
} catch (Exception se) {System.out.println("Error"+se);
jLabel6.setText("An Error Occur, Record Can not save");
}
Note: my database has seven (7) column but here in my code, I only used five (5) column, i did not use those column for Foreign Key.
How can i go about this please?
My run-time Error is
Errorjava.sql.SQLException: Column count doesn't match value count at row 1

New Topic/Question
Reply



MultiQuote



|