What method do I use to specify that a CallableStatement's parameter is a SQL CHAR type as opposed to a SQL VARCHAR? I cannot find a corresponding setChar method.

Joe Sam Shirah

Actually, you don't have to specify CHAR, VARCHAR or LONGVARCHAR. Use setString(), inherited from PreparedStatement, and the driver/DBMS will handle the proper type for you. Although the setString() javadoc only references VARCHAR and LONGVARCHAR, in Getting Started with the JDBC API the topic CHAR, VARCHAR, and LONGVARCHAR says this:

"Java programmers do not need to distinguish among the three types of JDBC strings, CHAR, VARCHAR, and LONGVARCHAR. Each can be expressed as a Java String, and it is possible to read and write an SQL statement correctly without knowing the exact data type that was expected."

The same is true for getString().

If you, for some reason, feel better directly specifying the type, you should be able to use this method, submitted by Gabriel Artaud:

Use setObject(int parameterIndex, Object x, int targetSqlType) with targetSqlType set to Types.CHAR.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact