准备好的语句中的整数和字符串

时间:2013-01-15 01:36:03

标签: java jsp netbeans

我的try子句中有这个...如果删除pst.setString(5, value5),它工作正常, 如果我删除所有整数值也可以工作,但是如果添加了所有整数和值5,我就无法工作......

try {
  Class.forName("org.postgresql.Driver");
  connection = DriverManager.getConnection(connectionURL, "username", "password");
  String sql ="UPDATE table1 SET value1 = ?, value2 = ?, value3 = ?, value4 = ? value5 = ? WHERE value6 = ? ";
  PreparedStatement pst = connection.prepareStatement(sql);

  Integer value1A = Integer.parseInt(value1),
  value2A = Integer.parseInt(value2),
  value2A = Integer.parseInt(value3),
  value2A = Integer.parseInt(value4);  

  pst.setInt(1, value1A);
  pst.setInt(2, value2A);
  pst.setInt(3, value3A);
  pst.setInt(4, value4A);
  pst.setString(5, value5);
  pst.setString(6, value6);

  int numRowsChanged = pst.executeUpdate();

  pst.close();
}

2 个答案:

答案 0 :(得分:5)

您在SQL中错过了逗号:

String sql ="UPDATE table1 SET value1 = ?, value2 = ?, value3 = ?, value4 = ?, value5 = ? WHERE value6 = ? ";
                                                                             ^

答案 1 :(得分:1)

你似乎错过了一个逗号?