You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2006/01/23 16:58:53 UTC

svn commit: r371561 [9/11] - in /db/derby/code/trunk/java: client/org/apache/derby/client/ client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ client/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/DerbyNe...

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Savepoint.java Mon Jan 23 07:58:34 2006
@@ -20,6 +20,8 @@
 
 package org.apache.derby.client.am;
 
+import java.sql.SQLException;
+
 public class Savepoint implements java.sql.Savepoint {
     // ----------------- internals -----------------------------------------------
 
@@ -43,19 +45,19 @@
 
     // ----------------- externals -----------------------------------------------
 
-    public int getSavepointId() throws SqlException {
+    public int getSavepointId() throws SQLException {
         if (savepointId_ != 0) {
             return savepointId_;
         } else {
-            throw new SqlException(agent_.logWriter_, "This is a named savepoint.");
+            throw new SqlException(agent_.logWriter_, "This is a named savepoint.").getSQLException();
         }
     }
 
-    public String getSavepointName() throws SqlException {
+    public String getSavepointName() throws SQLException {
         if (savepointName_ != null) {
             return savepointName_;
         } else {
-            throw new SqlException(agent_.logWriter_, "This is an un-named savepoint.");
+            throw new SqlException(agent_.logWriter_, "This is an un-named savepoint.").getSQLException();
         }
     }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Section.java Mon Jan 23 07:58:34 2006
@@ -135,7 +135,7 @@
         return 0;
     }
 
-    public Section getPositionedUpdateSection() throws java.sql.SQLException {
+    public Section getPositionedUpdateSection() throws SqlException {
         return agent_.sectionManager_.getPositionedUpdateSection(this);
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Mon Jan 23 07:58:34 2006
@@ -52,25 +52,53 @@
 // 2. What is the format and type of the Locale parameter? If there does, I would really like to know the format of the locale in order to decide the type of the Locale parameter. Even there does not either, the Locale parameter probably still needs to be kept there for future extension, and we need to figure out the format of the locale.
 // 3. What would be the format of the output message? Is this full message text ok or do we only need the explanation message corresponding to an SQL code. This somehow matters whether we need the Buffersize and Linewidth parameters for the stored procedure.
 // 4. What if the invocation of stored procedure failed (due to, eg, connection dropping)? In this case, we probably need to return some client-side message.
-
-public class SqlException extends java.sql.SQLException implements Diagnosable {
+//
+// Note that this class does NOT extend java.sql.SQLException.  This is because
+// in JDBC 4 there will be multiple subclasses of SQLException defined by the
+// spec.  So we can't also extend SQLException without having to create our
+// own mirror hierarchy of subclasses.
+//
+// When Derby is ready to throw an exception to the application, it catches
+// SqlException and converts it to a java.sql.SQLException by calling the
+// method getSQLException.
+//
+// It is also possible that internal routines may call public methods.
+// In these cases, it will need to wrap a java.sql.SQLException inside
+// a Derby SqlException so that the internal method does not have to throw
+// java.sql.SQLException.  Otherwise the chain of dependencies would quickly
+// force the majority of internal methods to throw java.sql.SQLException.
+// You can wrap a java.sql.SQLException inside a SqlException by using
+// the constructor <code>new SqlException(java.sql.SQLException wrapMe)</code)
+//
+public class SqlException extends Exception implements Diagnosable {
     protected static final int DEFAULT_ERRCODE = 99999;
-    java.lang.Throwable throwable_ = null;
     protected Sqlca sqlca_ = null; // for engine generated errors only
     protected String message_ = null;
     private String batchPositionLabel_; // for batched exceptions only
+    protected String sqlstate_ = null;
+    protected int errorcode_ = DEFAULT_ERRCODE;
+    protected String causeString_ = null;
+    protected SqlException nextException_;
+    protected Throwable throwable_;
     
     public static String CLIENT_MESSAGE_RESOURCE_NAME =
         "org.apache.derby.loc.clientmessages";
     
-    // The message utility instance we use to find messages
-    // It's primed with the name of the client message bundle so that
-    // it knows to look there if the message isn't found in the
-    // shared message bundle.
+    
+    /** 
+     *  The message utility instance we use to find messages
+     *  It's primed with the name of the client message bundle so that
+     *  it knows to look there if the message isn't found in the
+     *  shared message bundle.
+     */
     private static MessageUtil msgutil_ = 
         new MessageUtil(CLIENT_MESSAGE_RESOURCE_NAME);
 
-    
+    /** 
+     * The wrapped SQLException, if one exists
+     */
+    protected SQLException wrappedException_;
+  
     //-----------------constructors-----------------------------------------------
     // New constructors that support internationalized messages
     // The message id is wrapped inside a class so that we can distinguish
@@ -130,41 +158,65 @@
         this(logWriter, null, reason, sqlState, errorCode);
     }
 
-    private SqlException(LogWriter logWriter, java.lang.Throwable throwable, 
+    public SqlException(LogWriter logWriter, java.lang.Throwable throwable, 
         String reason, String sqlState, int errorCode ) {
-        super(reason, sqlState, errorCode);
         message_ = reason;
-        throwable_ = throwable;
+        sqlstate_ = sqlState;
+        errorcode_ = errorCode;
 
-        setCause();
+        setThrowable(throwable);
         
         if (logWriter != null) {
             logWriter.traceDiagnosable(this);
         }
         
     }
-        
-    protected void setCause()
+    
+    /**
+     * Set the cause of this exception based on its type and
+     * the current runtime version of Java
+     */
+    protected void setThrowable(Throwable throwable)
     {
-        // Store the throwable correctly depending upon its class
-        // and whether initCause() is available
-        if (throwable_ != null  )
+        throwable_ = throwable;
+        
+        // If the throwable is a SQL exception, use nextException rather
+        // than chained exceptions
+        if ( throwable instanceof SqlException )
         {
-            if ( throwable_ instanceof SQLException )
-            {
-                setNextException((SQLException)throwable_);
-            }
-            else if ( JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
+            setNextException((SqlException) throwable);
+        }
+        else if ( throwable instanceof SQLException )
+        {
+            setNextException((SQLException) throwable );
+        }
+        else if ( throwable != null )
+        {
+            // Set up a string indicating the cause if the current runtime
+            // doesn't support the initCause() method.  This is then used
+            // by getMessage() when it composes the message string.
+            if (JVMInfo.JDK_ID < JVMInfo.J2SE_14 )
             {
-    			initCause(throwable_);
+                causeString_ = " Caused by exception " + 
+                    throwable.getClass() + ": " + throwable.getMessage();
             }
             else
             {
-                message_ = message_ + " Caused by exception " + 
-                    throwable_.getClass() + ": " + throwable_.getMessage();
-
+                initCause(throwable);
             }
         }
+
+    }
+        
+    /**
+     * Wrap a SQLException in a SqlException.  This is used by internal routines
+     * so the don't have to throw SQLException, which, through the chain of 
+     * dependencies would force more and more internal routines to throw
+     * SQLException
+     */
+    public SqlException(SQLException wrapme)
+    {
+        wrappedException_ = wrapme;
     }
         
     // Constructors for backward-compatibility while we're internationalizng
@@ -211,6 +263,39 @@
 
     //--- End backward-compatibility constructors ----------------------
     
+    
+    /**
+     * Convert this SqlException into a java.sql.SQLException
+     */
+    public SQLException getSQLException()
+    {
+        if ( wrappedException_ != null )
+        {
+            return wrappedException_;
+        }
+                
+        // When we have support for JDBC 4 SQLException subclasses, this is
+        // where we decide which exception to create
+        SQLException sqle = new SQLException(getMessage(), getSQLState(), 
+            getErrorCode());
+
+        // If we're in a runtime that supports chained exceptions, set the cause 
+        // of the SQLException.
+         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
+        {
+            sqle.initCause(getCause());
+        }
+
+        // Set up the nextException chain
+        if ( nextException_ != null )
+        {
+            // The exception chain gets constructed automatically through 
+            // the beautiful power of recursion
+            sqle.setNextException(nextException_.getSQLException());
+        }
+        
+        return sqle;
+    }    
 
     // Label an exception element in a batched update exception chain.
     // This text will be prepended onto the exceptions message text dynamically
@@ -229,30 +314,87 @@
     }
 
     public String getMessage() {
+        if ( wrappedException_ != null )
+        {
+            return wrappedException_.getMessage();
+        }
+        
         if (sqlca_ != null) {
             message_ = ((Sqlca) sqlca_).getJDBCMessage();
         }
-
-        if (batchPositionLabel_ == null) {
-            return message_;
+        
+        if (batchPositionLabel_ != null) {
+            message_ = batchPositionLabel_ + message_;
         }
-
-        return batchPositionLabel_ + message_;
+        
+        if ( causeString_ != null ) {
+            // Append the string indicating the cause of the exception
+            // (this happens only in JDK13 environments)
+            message_ += causeString_;
+        }
+        
+        return message_;
     }
 
     public String getSQLState() {
+        if ( wrappedException_ != null )
+        {
+            return wrappedException_.getSQLState();
+        }
+        
         if (sqlca_ == null) {
-            return super.getSQLState();
+            return sqlstate_;
         } else {
             return sqlca_.getSqlState();
         }
     }
 
     public int getErrorCode() {
+        if ( wrappedException_ != null )
+        {
+            return wrappedException_.getErrorCode();
+        }
+        
         if (sqlca_ == null) {
-            return super.getErrorCode();
+            return errorcode_;
         } else {
             return sqlca_.getSqlCode();
+        }
+    }
+
+    public SqlException getNextException()
+    {
+        if ( wrappedException_ != null )
+        {
+            return new SqlException(wrappedException_.getNextException());
+        }
+        else
+        {
+            return nextException_;
+        }
+    }
+    
+    public void setNextException(SqlException nextException)
+    {
+        if ( wrappedException_ != null )
+        {
+            wrappedException_.setNextException(nextException.getSQLException());
+        }
+        else
+        {
+            nextException_ = nextException;
+        }        
+    }
+    
+    public void setNextException(SQLException nextException)
+    {
+        if ( wrappedException_ != null )
+        {
+            wrappedException_.setNextException(nextException);
+        }
+        else
+        {
+            nextException_ = new SqlException(nextException);
         }
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java Mon Jan 23 07:58:34 2006
@@ -245,7 +245,7 @@
                 if (cs != null) {
                     try {
                         cs.closeX();
-                    } catch (java.sql.SQLException doNothing) {
+                    } catch (SqlException doNothing) {
                     }
                 }
             }
@@ -260,7 +260,7 @@
                 return getMessage();
             } catch (SqlException e) {
                 // Invocation of stored procedure fails, so we return error message tokens directly.
-                exceptionThrownOnStoredProcInvocation_ = e;
+                exceptionThrownOnStoredProcInvocation_ = e.getSQLException();
                 chainDeferredExceptionsToAgentOrAsConnectionWarnings((SqlException) e);
                 return getUnformattedMessage();
             }
@@ -284,7 +284,7 @@
                         " See chained exception." +
                         " The stored procedure SYSIBM.SQLCAMESSAGE is not installed on server." +
                         " Contact your DBA.");
-                warningForStoredProcFailure.setNextException(current);
+                warningForStoredProcFailure.setNextException(current.getSQLException());
                 connection_.accumulate440WarningForMessageProcFailure(warningForStoredProcFailure);
             } else if (current.getErrorCode() == -444) {
                 SqlWarning warningForStoredProcFailure = new SqlWarning(agent_.logWriter_,
@@ -292,7 +292,7 @@
                         " See chained exception." +
                         " The stored procedure SYSIBM.SQLCAMESSAGE cannot be accessed on the server." +
                         " Contact your DBA.");
-                warningForStoredProcFailure.setNextException(current);
+                warningForStoredProcFailure.setNextException(current.getSQLException());
                 connection_.accumulate444WarningForMessageProcFailure(warningForStoredProcFailure);
             } else {
                 agent_.accumulateDeferredException(current);

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Mon Jan 23 07:58:34 2006
@@ -19,7 +19,7 @@
 */
 package org.apache.derby.client.am;
 
-
+import java.sql.SQLException;
 
 public class Statement implements java.sql.Statement, StatementCallbackInterface, UnitOfWorkListener {
 
@@ -370,17 +370,25 @@
 
     // ---------------------------jdbc 1------------------------------------------
 
-    public java.sql.ResultSet executeQuery(String sql) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeQuery", sql);
-            }
-            ResultSet resultSet = executeQueryX(sql);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "executeQuery", resultSet);
+    public java.sql.ResultSet executeQuery(String sql) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeQuery", sql);
+                }
+                ResultSet resultSet = executeQueryX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeQuery", resultSet);
+                }
+                return resultSet;
             }
-            return resultSet;
         }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+        
     }
 
     private ResultSet executeQueryX(String sql) throws SqlException {
@@ -405,16 +413,23 @@
         }
     }
 
-    public int executeUpdate(String sql) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeUpdate", sql);
-            }
-            int updateValue = executeUpdateX(sql);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+    public int executeUpdate(String sql) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql);
+                }
+                int updateValue = executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
             }
-            return updateValue;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
@@ -442,12 +457,19 @@
     }
 
     // The server holds statement resources until transaction end.
-    public void close() throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "close");
+    public void close() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "close");
+                }
+                closeX();
             }
-            closeX();
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
@@ -477,99 +499,155 @@
         }
     }
 
-    public int getMaxFieldSize() throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "getMaxFieldSize");
+    public int getMaxFieldSize() throws SQLException {
+        try
+        {
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceEntry(this, "getMaxFieldSize");
+            }
+            checkForClosedStatement();
+            return maxFieldSize_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        checkForClosedStatement();
-        return maxFieldSize_;
     }
 
-    public void setMaxFieldSize(int max) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setMaxFieldSize", max);
+    public void setMaxFieldSize(int max) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setMaxFieldSize", max);
+                }
+                checkForClosedStatement();
+                if (max < 0) {
+                    throw new SqlException(agent_.logWriter_, "Invalid maxFieldSize value: " + max);
+                }
+                maxFieldSize_ = max;
             }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    public int getMaxRows() throws SQLException {
+        try
+        {
             checkForClosedStatement();
-            if (max < 0) {
-                throw new SqlException(agent_.logWriter_, "Invalid maxFieldSize value: " + max);
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceExit(this, "getMaxRows", maxRows_);
             }
-            maxFieldSize_ = max;
+            return maxRows_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int getMaxRows() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getMaxRows", maxRows_);
+    public void setMaxRows(int maxRows) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setMaxRows", maxRows);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (maxRows < 0) {
+                    throw new SqlException(agent_.logWriter_, "Invalid maxRows value: " + maxRows);
+                }
+                maxRows_ = maxRows;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return maxRows_;
     }
 
-    public void setMaxRows(int maxRows) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setMaxRows", maxRows);
-            }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            if (maxRows < 0) {
-                throw new SqlException(agent_.logWriter_, "Invalid maxRows value: " + maxRows);
+    public void setEscapeProcessing(boolean enable) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setEscapeProcessing", enable);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
             }
-            maxRows_ = maxRows;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public void setEscapeProcessing(boolean enable) throws SqlException {
-        synchronized (connection_) {
+    public int getQueryTimeout() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setEscapeProcessing", enable);
+                agent_.logWriter_.traceExit(this, "getQueryTimeout", timeout_);
             }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+            return timeout_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int getQueryTimeout() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getQueryTimeout", timeout_);
+    public void setQueryTimeout(int seconds) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setQueryTimeout", seconds);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (seconds < 0) {
+                    throw new SqlException(agent_.logWriter_,
+                                           "Attempt to set a negative query timeout",
+                                           "XJ074.S");
+                }
+                if (seconds != timeout_) {
+                    timeout_ = seconds;
+                    doWriteTimeout = true;
+                }
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return timeout_;
     }
 
-    public void setQueryTimeout(int seconds) throws SqlException {
-        synchronized (connection_) {
+    public void cancel() throws SQLException {
+        try
+        {
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setQueryTimeout", seconds);
+                agent_.logWriter_.traceEntry(this, "cancel");
             }
             checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            if (seconds < 0) {
-                throw new SqlException(agent_.logWriter_,
-                                       "Attempt to set a negative query timeout",
-                                       "XJ074.S");
-            }
-            if (seconds != timeout_) {
-                timeout_ = seconds;
-                doWriteTimeout = true;
-            }
+            throw new SqlException(agent_.logWriter_, "cancel() not supported by server");
         }
-    }
-
-    public void cancel() throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "cancel");
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-        throw new SqlException(agent_.logWriter_, "cancel() not supported by server");
     }
 
-    public java.sql.SQLWarning getWarnings() throws SqlException {
+    public java.sql.SQLWarning getWarnings() throws SQLException {
         if (agent_.loggingEnabled()) {
             agent_.logWriter_.traceExit(this, "getWarnings", warnings_);
         }
         return warnings_;
     }
 
-    public void clearWarnings() throws SqlException {
+    public void clearWarnings() throws SQLException {
         synchronized (connection_) {
             if (agent_.loggingEnabled()) {
                 agent_.logWriter_.traceEntry(this, "clearWarnings");
@@ -588,54 +666,68 @@
     // ResultSet.getCursorName() should be used to
     // obtain the for update cursor name to use when executing a positioned update statement.
     // See Jdbc 3 spec section 14.2.4.4.
-    public void setCursorName(String name) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setCursorName", name);
-            }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            if (name == null || name.equals("")) {
-                throw new SqlException(agent_.logWriter_, "Invalid cursor name.");
-            }
+    public void setCursorName(String name) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setCursorName", name);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (name == null || name.equals("")) {
+                    throw new SqlException(agent_.logWriter_, "Invalid cursor name.");
+                }
 
-            // Invalid to set the cursor name if there are ResultSet's open on the Statement.
-            if (resultSet_ != null && resultSet_.openOnClient_) {
-                throw new SqlException(agent_.logWriter_, "Invalid operation: setCursorName() " +
-                        "called when there are open ResultSet's on the Statement.");
-            }
+                // Invalid to set the cursor name if there are ResultSet's open on the Statement.
+                if (resultSet_ != null && resultSet_.openOnClient_) {
+                    throw new SqlException(agent_.logWriter_, "Invalid operation: setCursorName() " +
+                            "called when there are open ResultSet's on the Statement.");
+                }
 
-            // Duplicate cursor names not allowed.
-            if (connection_.clientCursorNameCache_.containsKey(name)) {
-                throw new SqlException(agent_.logWriter_, "Duplicate cursor names are not allowed.");
-            }
-            connection_.clientCursorNameCache_.put(name, name);
+                // Duplicate cursor names not allowed.
+                if (connection_.clientCursorNameCache_.containsKey(name)) {
+                    throw new SqlException(agent_.logWriter_, "Duplicate cursor names are not allowed.");
+                }
+                connection_.clientCursorNameCache_.put(name, name);
 
-            // section_ is null for Statement objects.  We will defer the mapping of cursorName
-            // to section until when the query is executed.
-            if (section_ != null) {
-                agent_.sectionManager_.mapCursorNameToQuerySection(name, (Section) section_);
+                // section_ is null for Statement objects.  We will defer the mapping of cursorName
+                // to section until when the query is executed.
+                if (section_ != null) {
+                    agent_.sectionManager_.mapCursorNameToQuerySection(name, (Section) section_);
 
-                // This means we must subtitute the <users-cursor-name> with the <canned-cursor-name>
-                // in the pass-thru sql string "...where current of <canned-cursor-name>".
-                section_.setClientCursorName(name);
+                    // This means we must subtitute the <users-cursor-name> with the <canned-cursor-name>
+                    // in the pass-thru sql string "...where current of <canned-cursor-name>".
+                    section_.setClientCursorName(name);
+                }
+                cursorName_ = name;
             }
-            cursorName_ = name;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
     //----------------------- Multiple Results --------------------------
 
 
-    public boolean execute(String sql) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "execute", sql);
-            }
-            boolean b = executeX(sql);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "execute", b);
+    public boolean execute(String sql) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "execute", sql);
+                }
+                boolean b = executeX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "execute", b);
+                }
+                return b;
             }
-            return b;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
@@ -644,142 +736,226 @@
         return resultSet_ != null;
     }
 
-    public java.sql.ResultSet getResultSet() throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "getResultSet");
-            }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "getResultSet", resultSet_);
+    public java.sql.ResultSet getResultSet() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "getResultSet");
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "getResultSet", resultSet_);
+                }
+                return resultSet_;
             }
-            return resultSet_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int getUpdateCount() throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "getUpdateCount");
-            }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "getUpdateCount", updateCount_);
+    public int getUpdateCount() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "getUpdateCount");
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "getUpdateCount", updateCount_);
+                }
+                return updateCount_;
             }
-            return updateCount_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public boolean getMoreResults() throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "getMoreResults");
-            }
-            boolean resultIsResultSet = getMoreResultsX(CLOSE_ALL_RESULTS);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "getMoreResults", resultIsResultSet);
+    public boolean getMoreResults() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "getMoreResults");
+                }
+                boolean resultIsResultSet = getMoreResultsX(CLOSE_ALL_RESULTS);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "getMoreResults", resultIsResultSet);
+                }
+                return resultIsResultSet;
             }
-            return resultIsResultSet;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
     //--------------------------JDBC 2.0-----------------------------
 
-    public void setFetchDirection(int direction) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setFetchDirection", direction);
-            }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-            switch (direction) {
-            case java.sql.ResultSet.FETCH_FORWARD:
-            case java.sql.ResultSet.FETCH_REVERSE:
-            case java.sql.ResultSet.FETCH_UNKNOWN:
-                fetchDirection_ = direction;
-                break;
-            default:
-                throw new SqlException(agent_.logWriter_, "Invalid fetch direction " + direction);
+    public void setFetchDirection(int direction) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setFetchDirection", direction);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                switch (direction) {
+                case java.sql.ResultSet.FETCH_FORWARD:
+                case java.sql.ResultSet.FETCH_REVERSE:
+                case java.sql.ResultSet.FETCH_UNKNOWN:
+                    fetchDirection_ = direction;
+                    break;
+                default:
+                    throw new SqlException(agent_.logWriter_, "Invalid fetch direction " + direction);
+                }
             }
         }
-    }
-
-    public int getFetchDirection() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getFetchDirection", fetchDirection_);
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return fetchDirection_;
     }
 
-    public void setFetchSize(int rows) throws SqlException {
-        synchronized (connection_) {
+    public int getFetchDirection() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "setFetchSize", rows);
+                agent_.logWriter_.traceExit(this, "getFetchDirection", fetchDirection_);
             }
-            checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
-
-            if (rows < 0 || (maxRows_ != 0 && rows > maxRows_)) {
-                throw new SqlException(agent_.logWriter_, "Invalid fetch size " + rows);
-            }
-            fetchSize_ = rows;
+            return fetchDirection_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int getFetchSize() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getFetchSize", fetchSize_);
+    public void setFetchSize(int rows) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "setFetchSize", rows);
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+
+                if (rows < 0 || (maxRows_ != 0 && rows > maxRows_)) {
+                    throw new SqlException(agent_.logWriter_, "Invalid fetch size " + rows).getSQLException();
+                }
+                fetchSize_ = rows;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return fetchSize_;
     }
 
-    public int getResultSetConcurrency() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getResultSetConcurrency", resultSetConcurrency_);
+    public int getFetchSize() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceExit(this, "getFetchSize", fetchSize_);
+            }
+            return fetchSize_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return resultSetConcurrency_;
     }
 
-    public int getResultSetType() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getResultSetType", resultSetType_);
+    public int getResultSetConcurrency() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceExit(this, "getResultSetConcurrency", resultSetConcurrency_);
+            }
+            return resultSetConcurrency_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return resultSetType_;
     }
 
-    public void addBatch(String sql) throws SqlException {
-        synchronized (connection_) {
+    public int getResultSetType() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "addBatch", sql);
+                agent_.logWriter_.traceExit(this, "getResultSetType", resultSetType_);
             }
-            checkForClosedStatement();
-            sql = connection_.nativeSQLX(sql);
-            batch_.add(sql);
+            return resultSetType_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public void clearBatch() throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "clearBatch");
+    public void addBatch(String sql) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "addBatch", sql);
+                }
+                checkForClosedStatement();
+                sql = connection_.nativeSQLX(sql);
+                batch_.add(sql);
             }
-            checkForClosedStatement();
-            batch_.clear();
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int[] executeBatch() throws SqlException, BatchUpdateException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeBatch");
+    public void clearBatch() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "clearBatch");
+                }
+                checkForClosedStatement();
+                batch_.clear();
             }
-            int[] updateCounts = executeBatchX();
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "executeBatch", updateCounts);
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    public int[] executeBatch() throws SQLException, BatchUpdateException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeBatch");
+                }
+                int[] updateCounts = executeBatchX();
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeBatch", updateCounts);
+                }
+                return updateCounts;
             }
-            return updateCounts;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
@@ -787,7 +963,6 @@
         checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
         clearWarningsX(); // Per jdbc spec 0.7, and getWarnings() javadoc
         resultSetList_ = null;
-
         // Initialize all the updateCounts to indicate failure
         // This is done to account for "chain-breaking" errors where we cannot
         // read any more replies
@@ -796,30 +971,43 @@
             updateCounts[i] = -3;
         }
         flowExecuteBatch(updateCounts);
-
         return updateCounts;
     }
 
-    public java.sql.Connection getConnection() throws SqlException {
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getConnection", connection_);
+    public java.sql.Connection getConnection() throws SQLException {
+        try
+        {
+            checkForClosedStatement();
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceExit(this, "getConnection", connection_);
+            }
+            return connection_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        return connection_;
     }
 
     //--------------------------JDBC 3.0-----------------------------
 
-    public boolean getMoreResults(int current) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "getMoreResults", current);
-            }
-            boolean resultIsResultSet = getMoreResultsX(current);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "getMoreResults", resultIsResultSet);
+    public boolean getMoreResults(int current) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "getMoreResults", current);
+                }
+                boolean resultIsResultSet = getMoreResultsX(current);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "getMoreResults", resultIsResultSet);
+                }
+                return resultIsResultSet;
             }
-            return resultIsResultSet;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
@@ -861,95 +1049,151 @@
         return resultIsResultSet;
     }
 
-    public java.sql.ResultSet getGeneratedKeys() throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "getGeneratedKeys");
-        }
-        checkForClosedStatement();
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceExit(this, "getGeneratedKeys", generatedKeysResultSet_);
-        }
-        return generatedKeysResultSet_;
-    }
-
-    public int executeUpdate(String sql, int autoGeneratedKeys) throws SqlException {
-        synchronized (connection_) {
+    public java.sql.ResultSet getGeneratedKeys() throws SQLException {
+        try
+        {
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeUpdate", sql, autoGeneratedKeys);
+                agent_.logWriter_.traceEntry(this, "getGeneratedKeys");
             }
-            autoGeneratedKeys_ = autoGeneratedKeys;
-            int updateValue = executeUpdateX(sql);
+            checkForClosedStatement();
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                agent_.logWriter_.traceExit(this, "getGeneratedKeys", generatedKeysResultSet_);
             }
-            return updateValue;
+            return generatedKeysResultSet_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int executeUpdate(String sql, int columnIndexes[]) throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnIndexes);
+    public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, autoGeneratedKeys);
+                }
+                autoGeneratedKeys_ = autoGeneratedKeys;
+                int updateValue = executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        checkForClosedStatement();
-        throw new SqlException(agent_.logWriter_, "Driver not capable");
     }
 
-    public int executeUpdate(String sql, String columnNames[]) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnNames);
-            }
-            generatedKeysColumnNames_ = columnNames;
-            int updateValue = executeUpdateX(sql);
+    public int executeUpdate(String sql, int columnIndexes[]) throws SQLException {
+        try
+        {
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnIndexes);
             }
-            return updateValue;
+            checkForClosedStatement();
+            throw new SqlException(agent_.logWriter_, "Driver not capable");
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public boolean execute(String sql, int autoGeneratedKeys) throws SqlException {
-        synchronized (connection_) {
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "execute", sql, autoGeneratedKeys);
-            }
-            autoGeneratedKeys_ = autoGeneratedKeys;
-            boolean b = executeX(sql);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "execute", b);
+    public int executeUpdate(String sql, String columnNames[]) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnNames);
+                }
+                generatedKeysColumnNames_ = columnNames;
+                int updateValue = executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
             }
-            return b;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public boolean execute(String sql, int columnIndexes[]) throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "execute", sql, columnIndexes);
+    public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "execute", sql, autoGeneratedKeys);
+                }
+                autoGeneratedKeys_ = autoGeneratedKeys;
+                boolean b = executeX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "execute", b);
+                }
+                return b;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        checkForClosedStatement();
-        throw new SqlException(agent_.logWriter_, "Driver not capable");
     }
 
-    public boolean execute(String sql, String columnNames[]) throws SqlException {
-        synchronized (connection_) {
+    public boolean execute(String sql, int columnIndexes[]) throws SQLException {
+        try
+        {
             if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceEntry(this, "execute", sql, columnNames);
+                agent_.logWriter_.traceEntry(this, "execute", sql, columnIndexes);
             }
-            generatedKeysColumnNames_ = columnNames;
-            boolean b = executeX(sql);
-            if (agent_.loggingEnabled()) {
-                agent_.logWriter_.traceExit(this, "execute", b);
+            checkForClosedStatement();
+            throw new SqlException(agent_.logWriter_, "Driver not capable");
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    public boolean execute(String sql, String columnNames[]) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "execute", sql, columnNames);
+                }
+                generatedKeysColumnNames_ = columnNames;
+                boolean b = executeX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "execute", b);
+                }
+                return b;
             }
-            return b;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
     }
 
-    public int getResultSetHoldability() throws SqlException {
-        if (agent_.loggingEnabled()) {
-            agent_.logWriter_.traceEntry(this, "getResultSetHoldability");
+    public int getResultSetHoldability() throws SQLException {
+        try
+        {
+            if (agent_.loggingEnabled()) {
+                agent_.logWriter_.traceEntry(this, "getResultSetHoldability");
+            }
+            checkForClosedStatement();
+            return resultSetHoldability_;
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
         }
-        checkForClosedStatement();
-        return resultSetHoldability_;
     }
 
     // ----------------------- box car and callback methods ---------------------
@@ -2245,4 +2489,26 @@
             resultSet_.markAutoCommitted();
         }
     }
+    
+    protected SQLException jdbc3FeatureNotSupported(boolean checkStatement)
+        throws SQLException
+    {
+        try
+        {
+            if ( checkStatement )
+                checkForClosedStatement();
+            
+            throw new SqlException(agent_.logWriter_, "JDBC 3 method called - not yet supported");
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+    
+    protected SQLException jdbc3FeatureNotSupported() throws SQLException
+    {
+        return jdbc3FeatureNotSupported(true);
+    }
+
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java?rev=371561&r1=371560&r2=371561&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java Mon Jan 23 07:58:34 2006
@@ -20,6 +20,8 @@
 
 package org.apache.derby.client.am;
 
+import java.sql.SQLException;
+
 // Self-contained utilities.
 // Don't reference any other driver classes, except Configuration, from within this class.
 
@@ -238,6 +240,16 @@
     }
 
     // latestException is assumed to be non-null, accumulatedExceptions can be null
+    public static SQLException accumulateSQLException(SQLException latestException,
+                                                      SQLException accumulatedExceptions) {
+        if (accumulatedExceptions == null) {
+            return latestException;
+        } else {
+            accumulatedExceptions.setNextException(latestException);
+            return accumulatedExceptions;
+        }
+    }
+
     public static SqlException accumulateSQLException(SqlException latestException,
                                                       SqlException accumulatedExceptions) {
         if (accumulatedExceptions == null) {



Re: SQLException and missing stack trace

Posted by Sunitha Kambhampati <ks...@gmail.com>.
David W. Van Couvering wrote:

> Hi, Sunitha.  Did you log a JIRA for this?  I didn't see it...
>
I just did.  http://issues.apache.org/jira/browse/DERBY-1117

Thanks,
Sunitha.


Re: SQLException and missing stack trace

Posted by "David W. Van Couvering" <Da...@Sun.COM>.
Hi, Sunitha.  Did you log a JIRA for this?  I didn't see it...

David

David W. Van Couvering wrote:
> Yes, I agree this is a bug, thanks for catching this Sunitha.
> 
> David
> 
> Sunitha Kambhampati wrote:
> 
>> Hi all,
>>
>> I came across this when I was fixing another issue and realized that 
>> the error message didnt show me the actual underlying exception/cause.
>> cause is being lost in the following constructor in SqlException
>>
>>    public SqlException(LogWriter logwriter,
>>        MessageId msgid, Object[] args, Throwable cause)
>>    {
>>        this(
>>            logwriter,
>>            msgutil_.getCompleteMessage(
>>                msgid.msgid,
>>                args),
>>            ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
>>            ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));
>>    }
>>
>> maybe we should add setThrowable(cause) so we dont lose track of it.  
>> Thanks,
>> Sunitha.

Re: SQLException and missing stack trace

Posted by "David W. Van Couvering" <Da...@Sun.COM>.
Yes, I agree this is a bug, thanks for catching this Sunitha.

David

Sunitha Kambhampati wrote:
> Hi all,
> 
> I came across this when I was fixing another issue and realized that the 
> error message didnt show me the actual underlying exception/cause.
> cause is being lost in the following constructor in SqlException
> 
>    public SqlException(LogWriter logwriter,
>        MessageId msgid, Object[] args, Throwable cause)
>    {
>        this(
>            logwriter,
>            msgutil_.getCompleteMessage(
>                msgid.msgid,
>                args),
>            ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
>            ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));
>    }
> 
> maybe we should add setThrowable(cause) so we dont lose track of it.  
> Thanks,
> Sunitha.

Re: SQLException and missing stack trace

Posted by Sunitha Kambhampati <ks...@gmail.com>.
Hi all,

I came across this when I was fixing another issue and realized that the 
error message didnt show me the actual underlying exception/cause. 

cause is being lost in the following constructor in SqlException

    public SqlException(LogWriter logwriter,
        MessageId msgid, Object[] args, Throwable cause)
    {
        this(
            logwriter,
            msgutil_.getCompleteMessage(
                msgid.msgid,
                args),
            ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
            ExceptionUtil.getSeverityFromIdentifier(msgid.msgid));
    }

maybe we should add setThrowable(cause) so we dont lose track of it.   

Thanks,
Sunitha.

Re: SQLException and missing stack trace

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
"David W. Van Couvering" <Da...@Sun.COM> writes:

> Hi, Knut, you're right, I didn't see your original email, I do have to
> have a pretty tight filter to get anything done besides read email.
> 
> The intent was to "clone" the SqlException into a SQLException, but
> you're right, the stack trace and other context of the SqlException
> would be lost in the way it's done now.  Thanks very much for catching
> this!

I think "thanks for running into this" would be more precise. ;)
 
> If the SqlException itself was caused by another exception, I have to
> make sure that history gets saved too. 

That won't be a problem since that cause would be linked to the
SqlException, so you could do something like this in your application:

  try {
    ...
  } catch (SQLException sqle) {
    Throwable cause1 = sqle.getCause(); // SqlException
    Throwable cause2 = cause1.getCause(); // SqlException's cause
  }

> I'll log a bug and take a look at this.

Thanks for looking into this. You'll probably need to update a couple
of master files as well. At least, when I had the proposed changes in
my sandbox, some of the tests failed because of extra "Caused by:"
lines.

-- 
Knut Anders


Re: SQLException and missing stack trace

Posted by "David W. Van Couvering" <Da...@Sun.COM>.
Hi, Knut, you're right, I didn't see your original email, I do have to 
have a pretty tight filter to get anything done besides read email.

The intent was to "clone" the SqlException into a SQLException, but 
you're right, the stack trace and other context of the SqlException 
would be lost in the way it's done now.  Thanks very much for catching 
this!

If the SqlException itself was caused by another exception, I have to 
make sure that history gets saved too.  I'll log a bug and take a look 
at this.

David

Knut Anders Hatlen wrote:
> David, I didn't see you responding to this mail. I'm resending it with
> a different subject which is hopefully less likely to be regarded as
> junk by your mail filter. :)
> 
> Thanks,
> Knut Anders
> 
> Knut Anders Hatlen <Kn...@Sun.COM> writes:
> 
> 
>>Hi David, I'm sorry that I didn't notice it earlier, but I have found
>>a problem with the following method:
>>
>>
>>>Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
>>>URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=371561&r1=371560&r2=371561&view=diff
>>>==============================================================================
>>>--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
>>>+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Mon Jan 23 07:58:34 2006
>>>+    
>>>+    /**
>>>+     * Convert this SqlException into a java.sql.SQLException
>>>+     */
>>>+    public SQLException getSQLException()
>>>+    {
>>>+        if ( wrappedException_ != null )
>>>+        {
>>>+            return wrappedException_;
>>>+        }
>>>+                
>>>+        // When we have support for JDBC 4 SQLException subclasses, this is
>>>+        // where we decide which exception to create
>>>+        SQLException sqle = new SQLException(getMessage(), getSQLState(), 
>>>+            getErrorCode());
>>>+
>>>+        // If we're in a runtime that supports chained exceptions, set the cause 
>>>+        // of the SQLException.
>>>+         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
>>>+        {
>>>+            sqle.initCause(getCause());
>>>+        }
>>>+
>>>+        // Set up the nextException chain
>>>+        if ( nextException_ != null )
>>>+        {
>>>+            // The exception chain gets constructed automatically through 
>>>+            // the beautiful power of recursion
>>>+            sqle.setNextException(nextException_.getSQLException());
>>>+        }
>>>+        
>>>+        return sqle;
>>>+    }    
>>
>>I think
>>
>>    if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
>>    {
>>        sqle.initCause(getCause());
>>    }
>>
>>should have been
>>
>>    if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
>>    {
>>        sqle.initCause(this);
>>    }
>>
>>It is the SqlException that is the cause of the SQLException. The
>>cause of an SqlException is often null, and if we pass the null value
>>to SQLException.initCause(), we lose all of the driver internal stack
>>trace, and it makes debugging very difficult. All we get in the stack
>>trace is SqlException.getSQLException(), the top-level JDBC method and
>>the application stack.
>>
>>There is a similar problem in SqlWarning.getSQLWarning().
>>
>>-- 
>>Knut Anders
>>
>>
> 
> 
> 

SQLException and missing stack trace (was: svn commit: r371561 ...)

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
David, I didn't see you responding to this mail. I'm resending it with
a different subject which is hopefully less likely to be regarded as
junk by your mail filter. :)

Thanks,
Knut Anders

Knut Anders Hatlen <Kn...@Sun.COM> writes:

> Hi David, I'm sorry that I didn't notice it earlier, but I have found
> a problem with the following method:
> 
> > Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
> > URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=371561&r1=371560&r2=371561&view=diff
> > ==============================================================================
> > --- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
> > +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Mon Jan 23 07:58:34 2006
> > +    
> > +    /**
> > +     * Convert this SqlException into a java.sql.SQLException
> > +     */
> > +    public SQLException getSQLException()
> > +    {
> > +        if ( wrappedException_ != null )
> > +        {
> > +            return wrappedException_;
> > +        }
> > +                
> > +        // When we have support for JDBC 4 SQLException subclasses, this is
> > +        // where we decide which exception to create
> > +        SQLException sqle = new SQLException(getMessage(), getSQLState(), 
> > +            getErrorCode());
> > +
> > +        // If we're in a runtime that supports chained exceptions, set the cause 
> > +        // of the SQLException.
> > +         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
> > +        {
> > +            sqle.initCause(getCause());
> > +        }
> > +
> > +        // Set up the nextException chain
> > +        if ( nextException_ != null )
> > +        {
> > +            // The exception chain gets constructed automatically through 
> > +            // the beautiful power of recursion
> > +            sqle.setNextException(nextException_.getSQLException());
> > +        }
> > +        
> > +        return sqle;
> > +    }    
> 
> I think
> 
>     if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
>     {
>         sqle.initCause(getCause());
>     }
> 
> should have been
> 
>     if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
>     {
>         sqle.initCause(this);
>     }
> 
> It is the SqlException that is the cause of the SQLException. The
> cause of an SqlException is often null, and if we pass the null value
> to SQLException.initCause(), we lose all of the driver internal stack
> trace, and it makes debugging very difficult. All we get in the stack
> trace is SqlException.getSQLException(), the top-level JDBC method and
> the application stack.
> 
> There is a similar problem in SqlWarning.getSQLWarning().
> 
> -- 
> Knut Anders
> 
> 



Re: svn commit: r371561 [9/11] - in /db/derby/code/trunk/java: client/org/apache/derby/client/ client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ client/org/apache/derby/jdbc/ testing/org/apache/derbyTesting/functionTests/master/DerbyNe...

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Hi David, I'm sorry that I didn't notice it earlier, but I have found
a problem with the following method:

> Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
> URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=371561&r1=371560&r2=371561&view=diff
> ==============================================================================
> --- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
> +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Mon Jan 23 07:58:34 2006
> +    
> +    /**
> +     * Convert this SqlException into a java.sql.SQLException
> +     */
> +    public SQLException getSQLException()
> +    {
> +        if ( wrappedException_ != null )
> +        {
> +            return wrappedException_;
> +        }
> +                
> +        // When we have support for JDBC 4 SQLException subclasses, this is
> +        // where we decide which exception to create
> +        SQLException sqle = new SQLException(getMessage(), getSQLState(), 
> +            getErrorCode());
> +
> +        // If we're in a runtime that supports chained exceptions, set the cause 
> +        // of the SQLException.
> +         if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
> +        {
> +            sqle.initCause(getCause());
> +        }
> +
> +        // Set up the nextException chain
> +        if ( nextException_ != null )
> +        {
> +            // The exception chain gets constructed automatically through 
> +            // the beautiful power of recursion
> +            sqle.setNextException(nextException_.getSQLException());
> +        }
> +        
> +        return sqle;
> +    }    

I think

    if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
    {
        sqle.initCause(getCause());
    }

should have been

    if (JVMInfo.JDK_ID >= JVMInfo.J2SE_14 )
    {
        sqle.initCause(this);
    }

It is the SqlException that is the cause of the SQLException. The
cause of an SqlException is often null, and if we pass the null value
to SQLException.initCause(), we lose all of the driver internal stack
trace, and it makes debugging very difficult. All we get in the stack
trace is SqlException.getSQLException(), the top-level JDBC method and
the application stack.

There is a similar problem in SqlWarning.getSQLWarning().

-- 
Knut Anders