Derby
  1. Derby
  2. DERBY-1438

Text written by SQLException.toString differs between client and embedded driver

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 10.2.1.6
    • Fix Version/s: 10.2.1.6
    • Component/s: JDBC
    • Labels:
      None
    • Environment:
      Sun JDK 1.5

      Description

      The first part of the string written by SQLExeption.toString() differs
      between the Derby client driver and the embedded driver. The embedded
      driver writes:

      SQL Exception: Table/View 'DERBYDB' does not exist.

      while the client driver writes:

      java.sql.SQLException: Table/View 'DERBYDB' does not exist.

      It would be good if we changed this so the same text is written by
      both drivers. This reduces the difference seen when changing between
      client and embedded Derby and it make it possible to reduce the amount
      of sed-ing or the number of master file variants for some tests.

      1. DERBY-1438-rev2.diff
        1.01 MB
        David Van Couvering
      2. DERBY-1438.diff
        0.8 kB
        David Van Couvering

        Activity

        Olav Sandstaa created issue -
        David Van Couvering made changes -
        Field Original Value New Value
        Assignee David Van Couvering [ davidvc ]
        Hide
        David Van Couvering added a comment -

        I'll take a look at this and see what I can do. Thanks, Olav.

        Show
        David Van Couvering added a comment - I'll take a look at this and see what I can do. Thanks, Olav.
        Hide
        Olav Sandstaa added a comment -

        Personally, I prefer the text written by the embedded driver ("SQL Exception:") over the text written by the client driver ("java.sql.Exception:"), but with the introduction of the SQL exception hierarchy in Java SE 6 it might be better to use the exact exception name (e.g. "java.sql.IamSorryThisShouldNotHappenTodayException") which is what I think you get if you call SQLException.toString() and running with jdk 1.6.

        Show
        Olav Sandstaa added a comment - Personally, I prefer the text written by the embedded driver ("SQL Exception:") over the text written by the client driver ("java.sql.Exception:"), but with the introduction of the SQL exception hierarchy in Java SE 6 it might be better to use the exact exception name (e.g. "java.sql.IamSorryThisShouldNotHappenTodayException") which is what I think you get if you call SQLException.toString() and running with jdk 1.6.
        Hide
        David Van Couvering added a comment -

        We can't override the toString() method on the network client, as what's being returned to users is a vanilla java.sql.SQLException (or one of its subclasses in JDBC4). So it's going to do the default behavior and there's nothing we can do about it.

        In the embedded deriver, you'll also get the default toString() output, because in SQLExceptionFactory40 we're converting to vanilla java.sql.SQLException classes and its subtypes.

        Running pre-Java SE 6, the user gets an org.apache.derby.impl.jdbc.EmbedSQLException class, and that's kind of ugly to print out, and still wouldn't be consistent with the client.

        What I have done (see attached patch) is change the toString() override method in EmbedSQLException to print out "java.sql.SQLException" rather than just "SQL Exception". This is correct, in that EmbedSQLException is a subclass of java.sql.SQLException, and makes the client and the embedded drivers consistent.

        Unless anyone objects, I'll commit this (and resulting master output changes) after running derbyall.

        David

        Show
        David Van Couvering added a comment - We can't override the toString() method on the network client, as what's being returned to users is a vanilla java.sql.SQLException (or one of its subclasses in JDBC4). So it's going to do the default behavior and there's nothing we can do about it. In the embedded deriver, you'll also get the default toString() output, because in SQLExceptionFactory40 we're converting to vanilla java.sql.SQLException classes and its subtypes. Running pre-Java SE 6, the user gets an org.apache.derby.impl.jdbc.EmbedSQLException class, and that's kind of ugly to print out, and still wouldn't be consistent with the client. What I have done (see attached patch) is change the toString() override method in EmbedSQLException to print out "java.sql.SQLException" rather than just "SQL Exception". This is correct, in that EmbedSQLException is a subclass of java.sql.SQLException, and makes the client and the embedded drivers consistent. Unless anyone objects, I'll commit this (and resulting master output changes) after running derbyall. David
        David Van Couvering made changes -
        Attachment DERBY-1438.diff [ 12336826 ]
        Hide
        David Van Couvering added a comment -

        This attachment includes all updates to master files. It is a comment on master-based testing that a one-line change to source results in a 1MB overall patch because of master file changes.

        I tried to scan all the diffs but there was a lot to read. I did a couple of sanity tests to increase my confidence that I didn't miss anything:

        • I verified that the number of lines added was exactly equal to the number of lines removed
        • I verified that if I filtered out "java.sql.SQLException" and "SQL Exception" from the master file diffs, there was nothing else in there

        Reviews appreciated. I'm running derbyall again since a lot of changes have come in since my last run. If it passes, I"ll check it in tomorrow barring any review comments.

        =========

        svn status output:

        M java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java
        M java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests_ES.out
        M java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc30.out
        M java/testing/org/apache/derbyTesting/functionTests/master/parameterMapping.out
        M java/testing/org/apache/derbyTesting/functionTests/master/compressTable.out
        M java/testing/org/apache/derbyTesting/functionTests/master/importExportThruIJ.out
        M java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
        M java/testing/org/apache/derbyTesting/functionTests/master/TransactionTable.out
        M java/testing/org/apache/derbyTesting/functionTests/master/procedure.out
        M java/testing/org/apache/derbyTesting/functionTests/master/ieptests.out
        M java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests.out
        M java/testing/org/apache/derbyTesting/functionTests/master/streamingColumn.out
        M java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/importExport.out
        M java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ieptests.out
        M java/testing/org/apache/derbyTesting/functionTests/master/outparams.out
        M java/testing/org/apache/derbyTesting/functionTests/master/releaseCompileLocks.out
        M java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out

        Show
        David Van Couvering added a comment - This attachment includes all updates to master files. It is a comment on master-based testing that a one-line change to source results in a 1MB overall patch because of master file changes. I tried to scan all the diffs but there was a lot to read. I did a couple of sanity tests to increase my confidence that I didn't miss anything: I verified that the number of lines added was exactly equal to the number of lines removed I verified that if I filtered out "java.sql.SQLException" and "SQL Exception" from the master file diffs, there was nothing else in there Reviews appreciated. I'm running derbyall again since a lot of changes have come in since my last run. If it passes, I"ll check it in tomorrow barring any review comments. ========= svn status output: M java/engine/org/apache/derby/impl/jdbc/EmbedSQLException.java M java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests_ES.out M java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc30.out M java/testing/org/apache/derbyTesting/functionTests/master/parameterMapping.out M java/testing/org/apache/derbyTesting/functionTests/master/compressTable.out M java/testing/org/apache/derbyTesting/functionTests/master/importExportThruIJ.out M java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out M java/testing/org/apache/derbyTesting/functionTests/master/TransactionTable.out M java/testing/org/apache/derbyTesting/functionTests/master/procedure.out M java/testing/org/apache/derbyTesting/functionTests/master/ieptests.out M java/testing/org/apache/derbyTesting/functionTests/master/iepnegativetests.out M java/testing/org/apache/derbyTesting/functionTests/master/streamingColumn.out M java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/importExport.out M java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ieptests.out M java/testing/org/apache/derbyTesting/functionTests/master/outparams.out M java/testing/org/apache/derbyTesting/functionTests/master/releaseCompileLocks.out M java/testing/org/apache/derbyTesting/functionTests/master/statementJdbc20.out
        David Van Couvering made changes -
        Attachment DERBY-1438-rev2.diff [ 12337183 ]
        Hide
        Knut Anders Hatlen added a comment -

        David wrote:

        > We can't override the toString() method on the network client, as
        > what's being returned to users is a vanilla java.sql.SQLException
        > (or one of its subclasses in JDBC4). So it's going to do the
        > default behavior and there's nothing we can do about it.

        Actually, there is something we can do. The spec doesn't say that we
        can't create subclasses of the provided exception classes, so we can
        override the toString() method.

        I tried this code

        throw new SQLFeatureNotSupportedException("some error message") {
        public String toString()

        { return "SQLException: " + getMessage(); }

        };

        and it printed this message

        SQLException: some error message

        not

        java.sql.SQLFeatureNotSupportedException: some error message

        Show
        Knut Anders Hatlen added a comment - David wrote: > We can't override the toString() method on the network client, as > what's being returned to users is a vanilla java.sql.SQLException > (or one of its subclasses in JDBC4). So it's going to do the > default behavior and there's nothing we can do about it. Actually, there is something we can do. The spec doesn't say that we can't create subclasses of the provided exception classes, so we can override the toString() method. I tried this code throw new SQLFeatureNotSupportedException("some error message") { public String toString() { return "SQLException: " + getMessage(); } }; and it printed this message SQLException: some error message not java.sql.SQLFeatureNotSupportedException: some error message
        Hide
        David Van Couvering added a comment -

        Committed revision 424389.

        Show
        David Van Couvering added a comment - Committed revision 424389.
        David Van Couvering made changes -
        Fix Version/s 10.2.0.0 [ 11187 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Olav Sandstaa added a comment -

        I have verified that SQLException.toString() writes the same text in both network client and embedded driver.

        Thanks for fixing this, David!

        Show
        Olav Sandstaa added a comment - I have verified that SQLException.toString() writes the same text in both network client and embedded driver. Thanks for fixing this, David!
        Olav Sandstaa made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Dag H. Wanvik made changes -
        Component/s Newcomer [ 12310640 ]
        Gavin made changes -
        Workflow jira [ 12374246 ] Default workflow, editable Closed status [ 12799228 ]

          People

          • Assignee:
            David Van Couvering
            Reporter:
            Olav Sandstaa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development