尝试在表中插入数据时出现 INVALID COLUMN INDEX。
这是我的 DAO。不确定为什么存在无效的列索引。
try{
currentCon = JavaConnectionDB.getConnection();
PreparedStatement ps=currentCon.prepareStatement("insert into lecturer (lecturerID,lecturerFullname,lecturerPassword) values'"
+ lecturerID + "','" + lecturerFullname + "','" + lecturerPassword +"'");
ps.setString(1,Lbean.getLecturerID());
ps.setString(2,Lbean.getLecturerFullname());
ps.setString(3,Lbean.getLecturerPassword());
ps.executeUpdate();
}
有什么我错过的吗???先感谢您! :)
最佳答案
您需要像这样编写查询:
insert into lecturer (lecturerID,lecturerFullname,lecturerPassword) values(? , ? , ?);
问号是固定值的占位符,在执行 SQL 语句之前必须设置这些值。
关于java - 错误消息 : java. sql.SQLException:列索引无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35218771/