I'm trying to insert data to my database on sql and after I run my program an error occured and says :
[Microsoft][ODBC SQL Server Driver][SQL Server]Insert Error: Column name or number of supplied values does not match table definition.
how can I fix it? can anyone tell me what is wrong with my codes?
here is the codes :
private void btnInsertActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:****";
String user = "****";
String pass = "****";
Connection connection = DriverManager.getConnection(url, user, pass);
Statement statement = connection.createStatement();
String pIDNo = txtPatientID.getText();
String pFName = txtpFName.getText();
String pLName = txtpLName.getText();
String pMI = txtpMI.getText();
String sql = "INSERT INTO dbo.Patients VALUES (" +
(pIDNo)+",'"+(pFName)+"','"+(pLName)+"','"+(pMI)+"')";
statement.executeUpdate(sql);
JOptionPane.showMessageDialog(rootPane, "Patient Added!");
}catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
System.exit(1);
}
}
Here is the table info :
