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

MySQLPreparedStatement.setObject cannot handle java.lang.Character type

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.7, 1.1.8, 1.1.9, 1.2.0
    • 1.3.0
    • Other
    • None

    Description

      If setting a CHAR(1) database field, using Java char's or java.lang.Character, setObject fails with:

      Caused by: java.sql.SQLException: Could not set parameter in setObject, could not convert: class java.lang.Character to 1
      at org.mariadb.jdbc.internal.SQLExceptionMapper.getSQLException(SQLExceptionMapper.java:161)

      So where,

      setObject(final int parameterIndex, final Object x, final int targetSqlType)

      Object x is of type java.lang.Character
      and targetSqlType is 1 (java.sql.Types.CHAR)

      This can be fixed by adding a check for Character type, in setObject:

       else if (x instanceof Character) {
                  setString(parameterIndex, x.toString());
              }  

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              vgvid Vikram Goghari
              Votes:
              0 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.