[CONJ-185] MySQLPreparedStatement.setObject cannot handle java.lang.Character type Created: 2015-08-18  Updated: 2020-08-17  Resolved: 2015-09-15

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.1.7, 1.1.8, 1.1.9, 1.2.0
Fix Version/s: 1.3.0

Type: Bug Priority: Major
Reporter: Vikram Goghari Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by CONJ-820 MySQLPreparedStatement.setObject cann... Closed

 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());
        }  



 Comments   
Comment by Diego Dupin [ 2015-09-15 ]

corrected in 1.3.0.
test case added.

Comment by Riccardo Paolo Bestetti [ 2020-08-17 ]

Issue still present in 2.6.2

Generated at Thu Feb 08 03:13:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.