my dog learned polymorphism*
The moose likes JDBC and the fly likes Inserting data into oracle BLOB through JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting data into oracle BLOB through JDBC" Watch "Inserting data into oracle BLOB through JDBC" New topic
Author

Inserting data into oracle BLOB through JDBC

Prashant Naidu
Greenhorn

Joined: Jun 04, 2006
Posts: 1
Hi all,
I am trying to insert data into oracle BLOB through JDBC. I am able to insert the data using oracle.sql.BLOB which have methods like putBytes() and setBytes().

I have two concerns:
First one: I am inserting the data using the following code

ps = conn.prepareStatement(sql);
oracle.sql.BLOB newBlob = oracle.sql.BLOB.createTemporary(conn,false, oracle.sql.BLOB.DURATION_SESSION);

newBlob.putBytes(1,docout.toString().getBytes());
ps.setBlob(1,newBlob);
ps.execute();

sql statement contains one ? (i.e. bind variable), and docout is a stringBuffer which contains desired length of user (ex: 40,000).

Question: Is this the right way to insert blob data through JDBC or is there is any other better way? actually I want to insert Word documents into BLOB.
Second One: I have experimented this code with Oracle 9i JDBC and Oracle 10g JDBC.
Oracle 9i: In Oracle 9i jdbc driver putBytes() method is working, setBytes() is not working (error: unsupported feature).
Oracle 10g: In Oracle 10g jdbc driver putBytes() is working but it says putBytes is a deprecated method, setBytes() is working properly.

We still did not tested with Oracle 8i.

My concern is I have to write a program which can be used with any version of Oracle JDBC like 8i, 9i or 10g where I can use a single method
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Oracle publishes a complete working example program for BLOBs and CLOBs, the "LOB Datatype" example, here:
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting data into oracle BLOB through JDBC
 
Similar Threads
Classes12 or ojdbc14.jar ?
Problem with inserting blob
When to use setBytes() and setBinaryStream()
how to create BLOB and CLOB data
converting inputstream to BLOB