I am new to JDBC and I am trying to update 2 tables in my database, so I would like to do it in 1 transaction so if one query fails, the other should also fail. I would like to provide such behaviour or just have an opportunity to do rollback if one of them fails.
Here are my 2 queries:
int i = stmt.executeUpdate("INSERT INTO product (title, price, `status`) " +
"VALUES ( \"" + product.getTitle() + "\", " + product.getPrice() + ", " + product.getStatus().ordinal() + ");");
int j = stmt.executeUpdate("INSERT INTO product_categories (product_id, category_id) " +
"VALUES (last_insert_id(), " + categoryId + ");");