ERRORCODE=-4461

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.

Cause

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://aaaaabbbbb.xxx.com:50000/Sample";
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);
ex.printStackTrace();
}
}
Running the previous programs throws the following error:
Exception: com.ibm.db2.jcc.c.SqlException:
[jcc][1091][10417][3.64.96] Invalid data conversion: Parameter instance
P is invalid for the
requested conversion. ERRORCODE=-4461, SQLSTATE=42815
at com.ibm.db2.jcc.am.bd.a(bd.java:679)
at com.ibm.db2.jcc.am.bd.a(bd.java:60)
at com.ibm.db2.jcc.am.bd.a(bd.java:103)
at com.ibm.db2.jcc.am.ec.a(ec.java:1360)
at com.ibm.db2.jcc.am.ec.a(ec.java:1306)
at com.ibm.db2.jcc.am.jo.a(jo.java:2411)
at com.ibm.db2.jcc.am.jo.setObject(jo.java:2301)
at MAINCLASS.main(settest.java:18)

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

Answer

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.