2016-02-05 136 views
0

尝试在表格中插入数据时,获取INVALID COLUMN INDEX。错误消息:java.sql.SQLException:列索引无效

这是我的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(); 

      } 

有什么我错过了?先谢谢你! :)

+0

了解有关prepared statements.show您的表格定义 – Jens

回答

2

你需要写您的查询是这样的:

insert into lecturer (lecturerID,lecturerFullname,lecturerPassword) values(? , ? , ?); 

的问号是,你必须执行一个SQL语句之前设定的固定值的占位符。