Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-82

data type LONGVARCHAR not supported in setObject()

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.5
    • 1.1.8
    • None
    • None

    Description

      The MariaDB Connector fails to handle Strings correctly when the datatype LONGVARCHAR is used. The MySQL connector handles CHAR, VARCHAR and LONGVARCHAR identically. The MariaDB connector should do the same.
      This harms portability of MySQL Connector based projects.

      To reproduce:

      public class Test {
          public static void main(String[] args) throws Exception {
              final Connection jdbcConnection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/testdb", "root", null);
              final Statement stmt = jdbcConnection.createStatement();
       
              stmt.execute("CREATE TABLE exception (column1 TEXT NULL)");
              stmt.close();
       
              final PreparedStatement preparedStmt = jdbcConnection.prepareStatement("INSERT INTO `exception` (`column1`) VALUES ( ? )");
              
              preparedStmt.setObject(1, "This is a test!" , Types.LONGVARCHAR);
              preparedStmt.executeUpdate();
          }
      }

      Expected: Statement gets executed without errors
      But got: Exception below

      Exception in thread "main" java.sql.SQLException: Could not convert [This is a test!] to -1
      at org.mariadb.jdbc.internal.SQLExceptionMapper.getSQLException(SQLExceptionMapper.java:161)
      at org.mariadb.jdbc.MySQLPreparedStatement.setObject(MySQLPreparedStatement.java:1320)
      at aaa.Test.main(Test.java:45)

      Proposed patch:
      Change MySQLPreparedStatement#setObject(int, Object, int) to handle the character based SQL types identically:

                      case Types.CHAR:
                      case Types.VARCHAR:
      +               case Types.LONGVARCHAR: 
                      case Types.TIMESTAMP: 
                      case Types.TIME:
                          setString(parameterIndex, s);

      Attachments

        Activity

          People

            massimo.siani Massimo Siani (Inactive)
            dkessel Daniel Kessel
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.