File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Oracle/OAS and the fly likes Insert CLOB using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Insert CLOB using JDBC" Watch "Insert CLOB using JDBC" New topic
Author

Insert CLOB using JDBC

Liwuen Chew
Greenhorn

Joined: Mar 11, 2010
Posts: 24
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

Joined: Mar 11, 2010
Posts: 24
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!
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1732
    
  12

Thanks for solving your own topic!

And a SPECIAL thanks for posting the answer here!!


When you do things right, people won't be sure you've done anything at all.
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 742
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

Joined: Mar 22, 2008
Posts: 742
import oracle.jdbc.OraclePreparedStatement;
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert CLOB using JDBC