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

PreparedStatement.setString(null) causes Exception after filling Memo field

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I like to fill a MS Access Database table which contains a Memo field using PreparedStatement and INSERT. It works fine as long as I put a string with length less than 256 charakters into the Memo field. After filling in a string longer than 255 charakters PreparedStatement.setString(null) on the next VARCHAR column throws a SQLException 'Invalid precision value'.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In MS Access create a table which consists of a memo field followed by a simple VARCHAR column (TEXT(50)). Connect the database via ODBC interface and run the code example below.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      [Microsoft][ODBC Microsoft Access Driver]Invalid precision value.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class PreparedStatementInsert {

      private static String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
      private static String databaseName = "jdbc:odbc:PreparedStatementInsert";

      private static void insert() {
      PreparedStatement statement = null;
      Connection connection = null;
      try {
      Class.forName(driverName);
      } catch (ClassNotFoundException e) {
      System.out.println(e.getMessage());
      }

      try {
      connection = DriverManager.getConnection(databaseName, null, null);
      char[] m500 = new char[500];
      Arrays.fill(m500, 'm');
      String s500 = new String(m500);
      statement = connection.prepareStatement("INSERT INTO INSERT_TABLE VALUES (?, ?)");

      // This works
      statement.setString(1, "Memo text less than 256 characters");
      statement.setString(2, null);
      statement.execute();

      // This crashes
      statement.setString(1, s500);
      statement.setString(2, null);
      statement.execute();

      } catch (SQLException e) {
      System.out.println(e.getMessage());
      } finally {
      try {
      statement.close();
      connection.close();
      } catch (SQLException e1) {
      // ignore
      }
      }
      }

      public static void main(String[] args) {
      insert();
      System.out.println("Program finished.");
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not fill the memo field using PreparedStatement and INSERT. After inserting the whole row I set the memo value by PreparedStatement and UPDATE.

        Attachments

          Activity

            People

            Assignee:
            ahandasunw Amit Handa (Inactive)
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: