我正在尝试在 sql 上将数据插入到我的数据库中,并且在运行程序后发生错误并说:
[Microsoft][ODBC SQL Server Driver][SQL Server]Insert Error: Column name or number of supplied values does not match table definition.
我该如何解决?谁能告诉我我的代码有什么问题?
这是代码:
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);
}
}
这是表格信息: