Take the 2-minute tour ×

I am having CLOB column in Oracle Data Base , I want to insert String .

It works if I use setCharacterStream, but how to insert String by setBytes am getting exception. Please help me.

String s = "Hello How are you Data for CLOB column";
ps.setCharacterStream(1, new StringReader(s), s.length());

Exception Trace :

java.lang.NumberFormatException: For input string: "Hello How are you Data for CLOB column"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Byte.parseByte(Byte.java:151)
    at java.lang.Byte.parseByte(Byte.java:108)
    at colb.test.InertClob.main(InertClob.java:24)
share|improve this question
Here are two good examples: Handling CLOBS made easy, and Adding large object type to databaase. I do not think you need the "setByte()" at all. IMHO... –  paulsm4 Jan 19 '13 at 5:58
@paulsm4 Thank you....such nice link I even didn't think about such nice pstmt.setString(1, str);....... ? If you can make this as answer..... –  sunleo Jan 19 '13 at 6:07
my pleasure. Glad it helped! –  paulsm4 Jan 19 '13 at 7:11
setString is wrong here. May work/ may not, you should store an array of bytes to a Blob field. –  Alex Kreutznaer Jan 19 '13 at 8:52
how do you and why do you say that may or may not work Please explain...and I didn't ask about BLOB. –  sunleo Jan 19 '13 at 10:56

3 Answers 3

up vote 1 down vote accepted

Here are two good examples (with sample code, for select and insert):

  • Handling CLOBS made easy:


  • Adding large object type to databaase


share|improve this answer

please refer to the Java API DOC

Parses the string argument as a signed decimal byte. The characters in the string must all be decimal digits,

share|improve this answer

You should:

  1. Turn the String to a byte array by calling s.getBytes() for example or any other.
  2. Call setBytes method, not setByte

  3. When retrieving from the database, don't forget how you got the bytes, in order to restore the String properly.

share|improve this answer

Your Answer


