错误消息:java.sql.SQLException:列索引无效

error message: java.sql.SQLException: Invalid column index

我尝试在 table 中插入数据时得到无效的列索引。

这是我的 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 语句之前设置这些固定值。