考虑以下代码:
String updatestmt = "UPDATE marketplaces.amazon_merchant_fulfilled_orders SET order_status = ? WHERE amazon_order_id=?;";
Connection conn = connectToDatabase();
PreparedStatement pstInsert = conn.prepareStatement(updatestmt);
pstInsert.setString(1, orderId);
pstInsert.setString(2, status);
try {
int rowsAffected = pstInsert.executeUpdate();
System.out.println("Updated " + rowsAffected + " Line(s).");
...
执行此代码时,rowsAffected
始终为0
.
如果我将 updatetmt 更改为:
"UPDATE marketplaces.amazon_merchant_fulfilled_orders SET order_status = '"+status+"' WHERE amazon_order_id='"+orderId+"';";
并删除pstInsert.setString
代码工作正常的调用。
我的问题是为什么我不能使用准备好的语句来更新我的数据库?
平台:PostgreSQL 9.2 和 Java 7