JDBC – How to set char in a prepared statement

The JDBC Specification 4.0 in Appendix B (Data Type Conversion Tables) states the following conversions:

This table also shows the conversions used by the SQLInput reader methods, except that they use only the recommended conversions.

JDBC Type              Java Type
-------------------------------------------
CHAR                   String
VARCHAR                String
LONGVARCHAR            String
NUMERIC                java.math.BigDecimal
DECIMAL                java.math.BigDecimal
BIT                    boolean
BOOLEAN                boolean
TINYINT                byte
SMALLINT               short

TABLE B- 1  JDBC Types Mapped to Java Types

Therefore PreparedStatement.setString(1, String.valueOf(myChar)) should do the trick.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)