I want to insert into multiple tables of a java DB database but I want the whole process to be an atomic action i.e. if there is an insert error with one table then no table is inserted with data. I have used the java try-with-resources statement but it does not work as expected.
the code snippet is given below.
private void insertAlumnus() throws SQLException {
String insert = " INSERT INTO " + "APP.ALUMNUS " +
" (ALUMNUS_ID , FIRST_NAME , " +
" LAST_NAME , OTHER_NAME , " +
" YEAR_COMPLETED, EMPLOYEED , " +
" JOB_TITLE , EMAIL , TELEPHONE ) " +
"VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? )";
String cert = " INSERT INTO " + "APP.CERTIFICATE " +
" (CERTIFICATE ) " +
"VALUES ( ? )";
String dues = " INSERT INTO " + "APP.DUES " +
" (PAYMENT_YEAR , AMOUNT) " +
"VALUES (? , ? )";
try (Connection con = DriverManager.getConnection(host, uName, uPass)) {
try(PreparedStatement stm = c