• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Insert CLOB using JDBC

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!
I have a question regarding inserting clobs in oracle. I have a table

table: field1 - string ; field2 - number; field 3 - clob.

And I want to insert the values like this:
"insert into table values('abc',123,<don't know what to do here> )".

I am using a JDBC connection. Already tried with prepareStatement and things like that, but I cannot make it to work. Can someone explain how to make this kind of insert from java?

Thank you!
 
Liwuen Chew
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone! I found the way.
You must use an OraclePreparedStatement . It must be something like this:

String sql = "insert into table values('abc',123,?)";
OraclePreparedStatement st = (OraclePreparedStatement) connection.prepareStatement(sql); //where connection is your connection with Oracle
st.setStringForClob(1, /*String variable which contains the CLOB string*/);
st.executeUpdate();

And that's it!. Hope this helps anyone with the same issue!
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for solving your own topic!

And a SPECIAL thanks for posting the answer here!!
 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liwuen Chew wrote:Hello everyone! I found the way.
You must use an OraclePreparedStatement . It must be something like this:

String sql = "insert into table values('abc',123,?)";
OraclePreparedStatement st = (OraclePreparedStatement) connection.prepareStatement(sql); //where connection is your connection with Oracle
st.setStringForClob(1, /*String variable which contains the CLOB string*/);
st.executeUpdate();

And that's it!. Hope this helps anyone with the same issue!



It gives me the following error:

 
Farakh khan
Ranch Hand
Posts: 851
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import oracle.jdbc.OraclePreparedStatement;
reply
    Bookmark Topic Watch Topic
  • New Topic