This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes Insert file to Oracle's BLOB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert file to Oracle Watch "Insert file to Oracle New topic

Insert file to Oracle's BLOB

kwwong wong
Ranch Hand

Joined: Feb 15, 2002
Posts: 56
I using the following codes to insert the file in RAW LONG Column and it works O.K. But when I change the column type to BLOB, it throws the exception.

File file = new File (args[0]);
InputStream inStream = new FileInputStream (file);
PreparedStatement psmt = conn.prepareStatement
("INSERT INTO vp_doc (name,doc) VALUES (?, ?)");
psmt.setString (1, args[0]);
psmt.setBinaryStream (2, inStream,(int)file.length () );
psmt.execute ();

Below are the exception :

Exception in thread "main" java.sql.SQLException: No more data to read from sock
at oracle.jdbc.dbaccess.DBError.throwSqlException(
at oracle.jdbc.dbaccess.DBError.throwSqlException(
at oracle.jdbc.dbaccess.DBError.check_error(
at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(
at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(
at oracle.jdbc.ttc7.Oall7.receive(
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.ja
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.jav
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStateme
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePrepar
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStat
at UploadFile.main(

Who can point out my mistake ?
Sujatha Ranganathan

Joined: May 29, 2003
Posts: 12
You may want to have a look at the LOB Datatype Sample on OTN
Oracle Technology NetworkOracle Technology Network
kwwong wong
Ranch Hand

Joined: Feb 15, 2002
Posts: 56
The sample in OTN is an client application and using SELECT FOR UPDATE. Can I using this sample in Web Application ? I remember that SELECT FOR UPDATE cannot use in WEB application, is it true ?
GeeCON Prague 2014
subject: Insert file to Oracle's BLOB