[JDBC] setAutoCommit closes results?

Henry Lafleur HLafleur at phoenixforge.com
Wed Aug 2 12:02:37 EDT 2000


Just as a disclaimer, I'm a newbie with programmatic transactions. 

I downloaded the latest snapshot of FreeTDS_jdbc a couple of weeks ago. I
was testing transactions for a database access class that I am rewriting
(from J++ :-( ), and the setAutoCommit seems to close all result sets on all
statements. So, if I have a result set open and I want to turn off auto
commit to do a group of transactions, my result set goes away. This happens
when it executes the SQL on that connection (see The code). 

Is this correct? I guess this assumes that you'll be using transactions to
start and finish all result sets before you open any results? But, the way
that my class works is that it uses an open result set to get metadata to
build update SQL statements and the metadata disappears after setting
autocommit.

The code:
// in class Connection_base
   public void setAutoCommit(boolean value) throws SQLException
   {
      int    i;
      String sql = null;

      autoCommit = value;

      sql = sqlStatementToSetCommit();

      for(i=0; i<allStatements.size(); i++)
      {
         Statement  stmt = (Statement)allStatements.elementAt(i);

         {
            // Note-  stmt.execute implicitly eats the END_TOKEN
            // that will come back from the commit command
//--Here it executes the "set implicit_transactions off"
            stmt.execute(sql);
         }
      }
   }

// In class Statement
   public boolean execute(String sql) throws SQLException
   {
      SQLException   exception = null;
      
      if (tds == null)
      {
         throw new SQLException("Statement is closed");
      }

//-- Here it closes results from a previous query: i.e. my ResultSet -- I
won't show deeper...
      closeResults();
      clearWarnings();
      updateCount = -1;
      try
      {
         if (escapeProcessing)
         {
            sql = Tds.toNativeSql(sql, tds.getServerType());
         }
         tds.executeQuery(sql, this, timeout);
      }
      catch(java.io.IOException e)
      {
         throw new SQLException("Network error- " + e.getMessage());
      }
      catch(com.internetcds.jdbc.tds.TdsException e)
      {
         throw new SQLException("TDS error- " + e.getMessage());
      }
      return getMoreResults();
   } // execute()

Thanks,

Henry Lafleur



More information about the FreeTDS mailing list