Skip to main content

Posts

Showing posts with the label JDBC

JDBC transaction rollback

We are advised to rollback a JDBC transaction in the catch block that handles SQLException, just as shown in the code below. But what if a runtime exception is thrown while after midway in the transaction? Control will never go to the catch block and the transaction will never be rolled back.   import  java.sql.Connection; import  java.sql.DriverManager; import  java.sql.SQLException; import  java.sql.Statement; public class  UnderstandingJdbcTransactions  {    public static  void  main ( String []  args ) {      Connection conn =  null ;      Statement stmt =  null ;      String jdbcurl =  "jdbc:derby:testdb;create=true" ;      try  {        Class.forName ( "org.apache.derby.jdbc.EmbeddedDriver" ) ; ...