When you take the connection mark this connection as auto commit false
connection.setAutoCommit(false);
Once you succesfuly done your task commit that transaction
connection.commit();
In case of exception rollback that transaction
connection.rollback();
It is normal jdbc transaction you can go with other implementation of transaction as well .. Check this example here