Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Insert CLOB using JDBC

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1847
14
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for solving your own topic!

And a SPECIAL thanks for posting the answer here!!
 
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • 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: 833
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import oracle.jdbc.OraclePreparedStatement;
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic