0
有很多与此主题相关的问题,但我无法找到解决我的问题的方法。 我有一个“产品”表,我试图在netbeans中进行更新。 SQL语句在SQL开发工作,并且我已经加倍检查了我的连接等。在java中运行SQL更新语句
update products
set pvolume = 2, pprice = 15
where productid = 3;
输出:更新了1行。
但在netbeans中运行它不会执行。如果我错过了一些小的语法问题,我很抱歉,但我真的需要这种方法的帮助。
public boolean editProduct(int ID, String name, int volume, int quantity, String description, int price) {
boolean success = false;
Connection con = ConnectionTools.getInstance().getCurrentConnection();
String SQLString1 = "UPDATE products "
+ "SET pname = ?, "
+ "pvolume = ?, "
+ "pquantity = ?, "
+ "pdescription = ?, "
+ "pprice = ? "
+ "WHERE productID = ?";
PreparedStatement statement = null;
try {
statement = con.prepareStatement(SQLString1);
statement.setString(1, name);
statement.setInt(2,volume);
statement.setInt(3, quantity);
statement.setString(4, description);
statement.setInt(5, price);
statement.setInt(6, ID);
statement.executeUpdate();
success = true;
}catch (Exception e){
System.out.println("Insertion error!");
System.out.println(e.getMessage());
}finally {
try {
statement.close();
} catch (SQLException e) {
System.out.println("Statement close error!");
System.out.println(e.getMessage());
}
}
return success;
}
通过调试运行,似乎通过尝试尽可能statement.setInt(6号)运行,但随后并没有执行。这里是输出:
插入错误! ORA-00971:缺少SET关键字
任何帮助/建议,将不胜感激!谢谢
括号是完全可选的。请参阅文档中的update-set子句:http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10008.htm#i2126876 – 2013-04-06 11:28:40
只要尝试执行,仍会使用方括号捕获异常。除了没有括号,它在SQL开发工作正常...? – mcabe0131 2013-04-06 11:35:09