参数索引超出范围(2>参数个数,即1)

时间:2013-04-13 18:26:57

标签: java jdbc

String query = "insert into dept values(?,'?','?'))";
PreparedStatement pu=con.prepareStatement(query);
pu.setInt(1, 2);
pu.setString(2, "a");
pu.setString(3, "ss");
pu.execute(query);

2 个答案:

答案 0 :(得分:4)

删除问号周围的引号。

答案 1 :(得分:2)

单引号围绕占位符字符导致此错误。删除它们:

String query = "insert into dept values(?,?,?))";