An ERRORCODE=-4461 is returned when an invalid data conversion in Type 4 JCC connection occurs when the setObject() function is used.

When the Java:setObject function for character and string data types is used and returns an error -4461, this code means that an invalid data conversion occurs whenever using a JCC Type 4 connection. But the same function succeeds when a JCC Type 2 connection is used.


This error is returned for the Type 4 implementation of JDBC driver but not the Type 2 because, the Type 4 JDBC driver is a pure Java native driver that strictly follows the Java JDBC specifications. Whereas the Type2 JDBC driver is a CLI-based driver that is less strict with data type conversions.

The following code is a small test program to verify and fix the error:
<test program snip>
String url = "jdbc:db2://";
Connection con = DriverManager.getConnection(url,"userid","mypwd");
System.out.println("DB Sample Connected");
PreparedStatement pstmt =
con.prepareStatement("INSERT INTO table_name VALUES (?)");
// pstmt.setString (2, "P"); ===> SUCCESS
pstmt.setObject (2, new Character('P'), Types.CHAR ); ===> FAILs
pstmt.execute ();
catch (Exception ex) {
System.out.println("Exception: " + ex);
Running the previous programs throws the following error:
[jcc][1091][10417][3.64.96] Invalid data conversion: Parameter instance
P is invalid for the
requested conversion. ERRORCODE=-4461, SQLSTATE=42815
at MAINCLASS.main(

When pstmt.setObject is changed to pstmt.setString (the commented line that precedes the failing one), it inserts "P" successfully in the table.


The solution is to use the function setString in place of setObject wherever you are aware that input data is going to be a character or string.