我正在尝试将记录添加到数据库。我找不到这个函数的错误。任何人都可以帮忙吗?
public static void insertTable(int idEmployee , String First_Name , String Last_Name , String Password , int Sex , String Mail , int Employee_idEmployee ) throws Exception {
Connection conn = (Connection) getConnection() ;
try {
PreparedStatement insertStatement = (PreparedStatement) conn.prepareStatement("INSERT INTO employee (?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?)");
insertStatement.setInt(1, idEmployee);
insertStatement.setString(2, First_Name);
insertStatement.setString(3, Last_Name );
insertStatement.setString(4, Password);
insertStatement.setInt(5, Sex);
insertStatement.setString(6, Mail);
insertStatement.setInt(7 ,Employee_idEmployee);
insertStatement.close();
conn.close() ;
System.out.println("it's ok");
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
和主目录
insertTable(4 , "test" , "test" , "test" , 1 , "test" , 4 );
这是 prtSc 表:
最佳答案
指定列名称是修复的一部分。
你仍然缺少执行线
您没有 insertStatement.execute();
调用
关于java sql向表中插入记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37102916/