OpenJPA
  1. OpenJPA
  2. OPENJPA-1029

SQLServerDictionary causes NumberFormatException if MS SQL Server JDBC driver is used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-M2
    • Fix Version/s: 1.0.4, 1.2.2, 1.3.0, 2.0.0-M2
    • Component/s: third-party
    • Labels:
      None

      Description

      If the Microsoft SQL Server JDBC Driver v1.2 or 2.0 is used instead of the jTDS driver, then the SQLServerDictionary will throw an exception while trying to parse the driverName "Microsoft SQL Server JDBC Driver" to determine the server version. For the MS SQL JDBC driver, it should be using meta.getDatabaseMajorVersion() to determine the server version. Also, the MS SQL JDBC driver was not being recognized correctly, so driverVendor was being set to VENDOR_OTHER instead of VENDOR_MICROSOFT.

      java.lang.NumberFormatException: For input string: "JDBC"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
      at java.lang.Integer.parseInt(Integer.java:447)
      at java.lang.Integer.parseInt(Integer.java:497)
      at org.apache.openjpa.jdbc.sql.SQLServerDictionary.connectedConfiguration(SQLServerDictionary.java:92)
      at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:190)
      at org.apache.openjpa.jdbc.sql.DBDictionaryFactory.newDBDictionary(DBDictionaryFactory.java:100)
      at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:584)
      at org.apache.openjpa.persistence.query.TestQueryTimeout.setUp(TestQueryTimeout.java:89)
      at junit.framework.TestCase.runBare(TestCase.java:125)
      at org.apache.openjpa.persistence.test.PersistenceTestCase.runBare(PersistenceTestCase.java:455)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at org.apache.openjpa.persistence.test.PersistenceTestCase.run(PersistenceTestCase.java:182)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)

      1. OPENJPA-1029.patch
        6 kB
        Donald Woods
      2. OPENJPA-1029.patch
        9 kB
        Donald Woods
      3. OPENJPA-1029-13x.patch
        9 kB
        Donald Woods
      4. OPENJPA-1029-12x.patch
        9 kB
        Donald Woods
      5. OPENJPA-1029-10x.patch
        9 kB
        Donald Woods
      6. OPENJPA-1029.patch
        6 kB
        Donald Woods

        Issue Links

          Activity

          Hide
          Donald Woods added a comment -

          Patch that allows usage of the MS SQL Server JDBC drivers [1] and adds a test profile for v2.0 of the driver.
          [1] http://msdn.microsoft.com/en-us/data/aa937724.aspx

          Show
          Donald Woods added a comment - Patch that allows usage of the MS SQL Server JDBC drivers [1] and adds a test profile for v2.0 of the driver. [1] http://msdn.microsoft.com/en-us/data/aa937724.aspx
          Hide
          Donald Woods added a comment -

          Jeremy, can you take a look at this patch for me? It will have to be applied before OPENJPA-964-part1.patch for proper MS SQL Server support.

          Show
          Donald Woods added a comment - Jeremy, can you take a look at this patch for me? It will have to be applied before OPENJPA-964 -part1.patch for proper MS SQL Server support.
          Hide
          Milosz Tylenda added a comment -

          Donald, have you made sure we will not blow up when using the older Microsoft driver in these lines:

          + if (VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor)) {
          + if (meta.getDatabaseMajorVersion() >= 9) {

          meta.getDatabaseMajorVersion() comes with JDBC 3.

          Show
          Milosz Tylenda added a comment - Donald, have you made sure we will not blow up when using the older Microsoft driver in these lines: + if (VENDOR_MICROSOFT.equalsIgnoreCase(driverVendor)) { + if (meta.getDatabaseMajorVersion() >= 9) { meta.getDatabaseMajorVersion() comes with JDBC 3.
          Hide
          Donald Woods added a comment -

          What "older" driver are you referring to?
          On the Microsoft website at the link provided earlier, there are only 3 drivers to download -
          v1.1 - SQL Server 2000/2005 JDBC Driver 1.1 is JDBC 3.0 compliant and runs on the Java Runtime Environment (JRE) version 1.4 and later versions
          v1.2 - provides access to SQL Server 2000 and SQL Server 2005 from any Java application ... Type 4 JDBC driver ... is JDBC 3.0 compliant and runs on the Java Development Kit (JDK) version 1.4 and higher.
          v2.0 - provides access to SQL Server 2000, SQL Server 2005, and SQL Server 2008 from any Java application ... Type 4 JDBC driver ... is JDBC 4.0 compliant and runs on the Java Development Kit (JDK) version 5.0 or later.

          For OpenJPA, I would only suggest tolerating the 1.2 driver and supporting/recommending the 2.0 driver. In my testing both worked fine, but we only get a SQL status code back from the 2.0 driver for query timeouts.

          Show
          Donald Woods added a comment - What "older" driver are you referring to? On the Microsoft website at the link provided earlier, there are only 3 drivers to download - v1.1 - SQL Server 2000/2005 JDBC Driver 1.1 is JDBC 3.0 compliant and runs on the Java Runtime Environment (JRE) version 1.4 and later versions v1.2 - provides access to SQL Server 2000 and SQL Server 2005 from any Java application ... Type 4 JDBC driver ... is JDBC 3.0 compliant and runs on the Java Development Kit (JDK) version 1.4 and higher. v2.0 - provides access to SQL Server 2000, SQL Server 2005, and SQL Server 2008 from any Java application ... Type 4 JDBC driver ... is JDBC 4.0 compliant and runs on the Java Development Kit (JDK) version 5.0 or later. For OpenJPA, I would only suggest tolerating the 1.2 driver and supporting/recommending the 2.0 driver. In my testing both worked fine, but we only get a SQL status code back from the 2.0 driver for query timeouts.
          Hide
          Milosz Tylenda added a comment -

          I was referring to v1.2 but from your research we can see we are safe even with v1.1.

          +1 for tolerating v1.2 and recommending v2.0. Allowing only v2.0 seems too restrictive to me as, from what I can see, this is very fresh stuff. A note on this could be added to Supported Databases section in the manual.

          Show
          Milosz Tylenda added a comment - I was referring to v1.2 but from your research we can see we are safe even with v1.1. +1 for tolerating v1.2 and recommending v2.0. Allowing only v2.0 seems too restrictive to me as, from what I can see, this is very fresh stuff. A note on this could be added to Supported Databases section in the manual.
          Hide
          Donald Woods added a comment -

          Thanks for the review. I'll attach an updated patch that includes the Doc updates, along with setting a ne VENDOR_JTDS for the old driver, so we can differentiate the two.

          Show
          Donald Woods added a comment - Thanks for the review. I'll attach an updated patch that includes the Doc updates, along with setting a ne VENDOR_JTDS for the old driver, so we can differentiate the two.
          Hide
          Donald Woods added a comment -

          Updated patch which does not log cursor or pooling warnings if using the v2.0 driver.

          Show
          Donald Woods added a comment - Updated patch which does not log cursor or pooling warnings if using the v2.0 driver.
          Hide
          Donald Woods added a comment -

          The doc updates were included in OPENJPA-1033, as I had other db/driver updates in-progress....

          Show
          Donald Woods added a comment - The doc updates were included in OPENJPA-1033 , as I had other db/driver updates in-progress....
          Hide
          Donald Woods added a comment -

          Patches to allow usage of the MS SQL Server JDBC Driver v1.2 or 2.0 with OpenJPA 1.0.x, 1.2.x and 1.3.x.
          Also adds a test-mssql profile to the openjpa-persistence-jdbc/pom.xml for easier testing.

          Show
          Donald Woods added a comment - Patches to allow usage of the MS SQL Server JDBC Driver v1.2 or 2.0 with OpenJPA 1.0.x, 1.2.x and 1.3.x. Also adds a test-mssql profile to the openjpa-persistence-jdbc/pom.xml for easier testing.
          Hide
          Donald Woods added a comment -

          Updated patches that protect against a null driverName being returned from DatabaseMetaData and cleans up some of the conditional statements.

          Show
          Donald Woods added a comment - Updated patches that protect against a null driverName being returned from DatabaseMetaData and cleans up some of the conditional statements.
          Hide
          Donald Woods added a comment -

          Updated patch for trunk that protects against a possible null driverName being returned from DatabaseMetaData and cleans up some of the conditional statements.

          Show
          Donald Woods added a comment - Updated patch for trunk that protects against a possible null driverName being returned from DatabaseMetaData and cleans up some of the conditional statements.
          Hide
          Jeremy Bauer added a comment -

          Committed OPENJPA-1029.patch dated 2009-04-16 10:15 AM to trunk for Donald under revision 765841.

          Show
          Jeremy Bauer added a comment - Committed OPENJPA-1029 .patch dated 2009-04-16 10:15 AM to trunk for Donald under revision 765841.
          Hide
          Donald Woods added a comment -

          Mike, please consider the patches for the maintenance branches. Thanks.

          Show
          Donald Woods added a comment - Mike, please consider the patches for the maintenance branches. Thanks.
          Hide
          Donald Woods added a comment -

          resolving as fixed in trunk

          Show
          Donald Woods added a comment - resolving as fixed in trunk

            People

            • Assignee:
              Michael Dick
              Reporter:
              Donald Woods
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development