Hello all. I am a first time poster, but have found coderanch to be very helpful the last couple of months, thanks. My question concerns insertion of a String into a Db BLOB field. My original code was thus:
String att_pdfb = <a large string coming from xml>;
PreparedStatement updt_att_st = dbConn.prepareStatement("UPDATE Attachment SET update_date_time = SYSDATE, contents_raw_data_blob = ? WHERE application_id =? AND file_name = ? AND attachment_type_code = ?");
java.lang.ClassCastException: java.lang.String cannot be cast to oracle.sql.BLOB
Could someone explain this to me? I have looked around on the web, I see that others have encountered this, but I can't seem to determine if this is a bug, and if so, it's been resolved, or if perhaps I need an updated ojdbc.jar. I am currently using ojdbc6.jar. I don't see a programming error - not that there isn't one there! This is not terribly important, I was just trying to avoid charset/encoding issues with the conversion from String to bytes, by inserting the String directly into the Db as BLOB.
I should note that I use setObject throughout my app with types DOUBLE & INTEGER, with no issues.
A String is not a BLOB.
setObject attempts to find a setter that maps the input Type with the SQL datatype.
In this case there is no match for String and Blob.
Seth A Jackson wrote:I should note that I use setObject throughout my app with types DOUBLE & INTEGER, with no issues.
In these case presumably the types passed in were doubles and integers respectively?
Seth A Jackson
posted 5 years ago
Hi Dave. Thanks for the reply. I agree that a String is not a BLOB, but I figure since a String inherits from java.lang.Object, it is an object, and so I figure the setObject should work. And incidentally, the instances where I use setObject with DOUBLE & INTEGER, I am still trying to map a string in there, with no problem. Here's an example: CS.setObject(235, msg_map_data.get("application_fee"), java.sql.Types.DOUBLE); where msg_map_data contains strings for both the keys & the values. Granted, I'm using this with a Callable Statement, not a Prepared Statement, but I wouldn't think that would cause this issue. Am I wrong? What really seems weird to me is that the exception is saying I'm trying to cast a String to oracle.sql.BLOB, but I'm not; I'm trying to cast to a java.sql.Type.BLOB. This is very strange to me. Seth
mooooooo ..... tiny ad ....
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop