Consider the following code:
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).");
...
When this code is executed, rowsAffected is always 0.
If I change updatestmt to :
"UPDATE marketplaces.amazon_merchant_fulfilled_orders SET order_status = '"+status+"' WHERE amazon_order_id='"+orderId+"';"; and remove the pstInsert.setString calls the code works fine.
My question is why am I unable to use prepared statements to update my database?
Platform: PostgreSQL 9.2 and Java 7
You’re setting the parameters in wrong order. Note:
And you’re sending
Change the order to make it work