Bug #1901 PreparedStatement.setObject() and CLOB, BLOB data
Submitted: 20 Nov 2003 6:23 Modified: 5 Dec 2003 5:50
Reporter: Christian Gruber Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.0.9 OS:Linux (Linux)
Assigned to: Mark Matthews CPU Architecture:Any

[20 Nov 2003 6:23] Christian Gruber
Description:
The PreparedStatement.setObject() method does not work for objects of the type Types.CLOB and Types.BLOB. When calling this method, an exception is thrown ("Unknown Types value").

How to repeat:
pstat.setObject(1, "hello", Types.CLOB);
pstat.setObject(2, new byte[]{0x1, 0x2}, Types.BLOB);

Suggested fix:
*** old/mysql-connector-java-3.0.9-stable/com/mysql/jdbc/PreparedStatement.java     Wed Oct  8 00:51:35 2003
--- new/mysql-connector-java-3.0.9-stable/com/mysql/jdbc/PreparedStatement.java Thu Nov 20 15:07:12 2003
*************** public class PreparedStatement extends c
*** 841,854 ****
--- 841,865 ----

                      break;

+                 case Types.CLOB:
+                     if (parameterObj instanceof Clob) {
+                         setClob(parameterIndex, (Clob)parameterObj);
+                     } else {
+                         setString(parameterIndex, parameterObj.toString());
+                     }
+                     break;
+
                  case Types.BINARY:
                  case Types.VARBINARY:
                  case Types.LONGVARBINARY:
+                 case Types.BLOB:

                      if (parameterObj instanceof String) {
                          setBytes(parameterIndex,
                              StringUtils.getBytes((String) parameterObj,
                                  this.charConverter, this.charEncoding));
+                     } else if (parameterObj instanceof Blob) {
+                         setBlob(parameterIndex, (Blob)parameterObj);
                      } else {
                          setBytes(parameterIndex, (byte[]) parameterObj);
                      }
[5 Dec 2003 5:50] Mark Matthews
This is a dupe of Bug#1786, which has already been fixed.