Skip site navigation (1) Skip section navigation (2)

JDBC Trouble when exception appears .

From: "Nicolas Paymal" <npaymal(at)instranet(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: JDBC Trouble when exception appears .
Date: 2002-03-05 09:52:28
Message-ID: LJEIJOMPNLMBFJLMFLKAMEAMCBAA.npaymal@instranet.com (view raw or flat)
Thread:
Lists: 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

Next:From: Arkadiusz MiskiewiczDate: 2002-03-06 09:18:44
Subject: regression - postgresql 7.2 on power pc/linux
Previous:From: JustinDate: 2002-03-05 02:50:22
Subject: Re: postmaster problem....

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group