JDBC Trouble when exception appears . - Mailing list pgsql-bugs

From Nicolas Paymal
Subject JDBC Trouble when exception appears .
Date
Msg-id LJEIJOMPNLMBFJLMFLKAMEAMCBAA.npaymal@instranet.com
Whole thread Raw
List pgsql-bugs
Hello,
I got some pb with this configuration database pgsql 7.1 and connect with
jdbc driver from 7.2


I notice something that could be a jdbc bugs :
when connection is not set to autocommit (setAutocommit(false))
When you catch an exception, the next requests until the next commit are
totaly ingored ex code :

import java.sql.*;
import java.io.*;

class TestJDBC2_Pg {


   static private String driver = "org.postgresql.Driver";
   private static String url    =
"jdbc:postgresql://10.0.1.42:5432/pgdb?compatible=7.1"; // compatible 7.1
and 7.2




   static void main(String argv[]) throws Exception{

      Connection con        = null;
      Statement  statement  = null;
      ResultSet  rset       = null;

      try {
         Class.forName(driver).newInstance();
         con = DriverManager.getConnection(url, "user", "passwd");
         con.setAutoCommit(false);
         statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
      }
         catch (java.sql.SQLException e) {System.out.println("plaintage sql"
+e );
      }
         String strquery = "SELECT VALUE FROM WRONGTABLENAME\n";
         System.out.println(strquery);
      try {
         String result;
         rset= statement.executeQuery(strquery);
         if (rset !=null && rset.next())
             result= rset.getString("VALUE");
         int i=0;
         con.commit();
      }
         catch (java.sql.SQLException e) {System.out.println("error sql "
+e );
         //con.rollback();
      }

      strquery = "DROP INDEX WRONGINDEXNAME\n";
      System.out.println(strquery);

      try {
         statement.executeUpdate(strquery);
         int i=0;
         con.commit();
      }
         catch (java.sql.SQLException e) {System.out.println("error sql "
+e );
      }
   }
}

excecute this code  As you can see the second query is not excecuted (no
exception appears);

this does not appears if I do not comment the rollback() insinde the catch
exception (in red);

but you understand that during a connection I don't always what to rollback
all modif when I catch an exception.

So that cause me a lots of problems .

Is there any solutions ?

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Bug #613: Sequence values fall back to previously checkpointed
Next
From: Eric Lu
Date:
Subject: referential constraint bug