Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8038751

Java 1.6/7 64bit JDBC-ODBC bridge throws "Invalid string or buffer length".

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Won't Fix
    • Affects Version/s: 6u45, 7u21
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_45"
      Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)


      The same issue happens with jdk 1.7 u21 64bit also:

      http://www.developpez.net/forums/d1349772/logiciels/solutions-d-entreprise/business-intelligence/talend/developpement-jobs/microsoft-odbc-driver-manager-invalid-string-or-buffer-length/

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]
      Microsoft Windows 2008 64bit
      And All windows 64bit platforms

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      A 64bit ODBC DSN is required, this issue can happen on a lots of odbc drivers:
      access, excel, sql server, mysql, teradata, ...

      Tested with access odbc driver 2010, 2013 64bit

      A DESCRIPTION OF THE PROBLEM :
      The test codes always fails when get column data via ResultSet.getObject()/getString(), on jdk 1.6/1.7,
      But it runs well with 32bit jvm/32bit ODBC DSN

      This issue can happen with other odbc drivers: access 2010/2013, excel, sql server, mysql, teradata, etc,...
      It is not a problem of some odbc driver.

      The ODBC manager's trace file shows that SQLGetData function was invoked with wrong value of parameter BufferLength.
      I believe it was caused by JDBC-ODBC bridge native codes, that doesn't initialize high 4 bytes of parameter BufferLength, it explains why this issue happens on 64bit jvm only and randomly.

      csbase.jar" "co 12f4-10e8 ENTER SQLGetData
                  HSTMT 0x000000005DE55380
                  UWORD 1
                  SWORD 1 <SQL_C_CHAR>
                  PTR 0x000000005DED3890
                  SQLLEN -4294967040 <---- Wrong value of parameter BufferLength, hex: FFFFFFFF00000100. The high 4 bytes is wrong.
                  SQLLEN * 0x00000000603BF1D0

      csbase.jar" "co 12f4-10e8 EXIT SQLGetData with return code -1 (SQL_ERROR)
                  HSTMT 0x000000005DE55380
                  UWORD 1
                  SWORD 1 <SQL_C_CHAR>
                  PTR 0x000000005DED3890
                  SQLLEN -4294967040
                  SQLLEN * 0x00000000603BF1D0

                  DIAG [S1090] [Microsoft][ODBC Driver Manager] Invalid string or buffer length (0)



      SUCCESSFUL LOG of fetching data:
      csbase.jar" "co 12f4-10e8 ENTER SQLGetData
                  HSTMT 0x000000005DE55380
                  UWORD 1
                  SWORD 1 <SQL_C_CHAR>
                  PTR 0x000000005DED3890
                  SQLLEN 256 <---- Right value of parameter BufferLength
                  SQLLEN * 0x00000000603BF160

      csbase.jar" "co 12f4-10e8 EXIT SQLGetData with return code 0 (SQL_SUCCESS)
                  HSTMT 0x000000005DE55380
                  UWORD 1
                  SWORD 1 <SQL_C_CHAR>
                  PTR 0x000000005DED3890 [ 42] "&t=0504&d=111111&a=04&g=3&u=0&i=1111111259"
                  SQLLEN 256
                  SQLLEN * 0x00000000603BF160 (42)


      REGRESSION. Last worked in version 6u43

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1 Download northwind sample db tempale and Create database, then create a 64bit ODBC DSN points to this access accdb file. Or you can create DSN with use any other access file.

      Access Northwind sample file download from: http://office.microsoft.com/en-us/templates/northwind-sales-web-database-TC101114818.aspx


      2 Run a simple jdbc test program:

      3 Get exception when fetching data

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      There should be no exception thrown.
      ACTUAL -
      Get exception, full stack trace:
      Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
            at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
            at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getObject(JdbcOdbcResultSet.java:1678)
            at C46379.main(C46379.java:17)


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.sql.*;


      public class AccessODBC64bitTest {

          public static void main(String[] args)
              throws Throwable
          {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection conn = DriverManager.getConnection("jdbc:odbc:Northwind", "", "");
              
              Statement stmt = conn.createStatement();
              for(int i=0;i<10;i++){
                  ResultSet rs = stmt.executeQuery("SELECT * FROM Customers");
                  int columnCount = rs.getMetaData().getColumnCount();
                  while(rs.next()){
                      for(int j=1;j<=columnCount;j++)
                          rs.getObject(j);
                  }
                  rs.close();
                  System.out.println("RUN QUERY #"+i+" times");
              }
              conn.close();

          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      There is no workaround yet.

        Attachments

          Activity

            People

            Assignee:
            lancea Lance Andersen
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: