The moose likes JDBC and Relational Databases and the fly likes problem in inserting pdf file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem in inserting pdf file" Watch "problem in inserting pdf file" New topic

problem in inserting pdf file

Shyam Sunder

Joined: Dec 23, 2006
Posts: 24
This is my source code for inserting pdf file into oracle.
This code is working for only small size pdf (like 16 kb) if iam tring to insert a pdf file which is more than 2 mb.

Its giving the exception as given below.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class PDFConnect

public static void main(String args[])
Connection conn = DriverManager.getConnection("jdbcracle:thin:@", "TESTPTS", "TESTPTS");
System.out.println("connection established");
PreparedStatement ps = conn.prepareStatement("insert into DEMOBLOB values(?)");
System.out.println("insert executed");
File photo= new File("D:/Thinkingjava.pdf");
System.out.println("image loaded ");
FileInputStream photostream= new FileInputStream(photo);
System.out.println("photo taken");


catch(Exception e)

connection established
insert executed
image loaded
photo taken
java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested

at oracle.jdbc.dbaccess.DBError.throwSqlException(
at oracle.jdbc.ttc7.TTIoer.processError(
at oracle.jdbc.ttc7.Oall7.receive(
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(
at oracle.jdbc.driver.OracleStatement.executeNonQuery(
at oracle.jdbc.driver.OracleStatement.doExecuteOther(
at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(
at oracle.jdbc.driver.OracleStatement.doExecute(
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(
at PDFConnect.main(
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

You should look up tutorials on blobs, inserting them can be tricky.

Last I recall in some systems it requires two passes for an insert. The first insert without the blob creates the db record and makes available a pointer to the blob. Then an update is performed using that pointer. That would seem to support the error, it doesn't want to insert a blob directly, it wants the db to create one and then you to set it.

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: problem in inserting pdf file
It's not a secret anymore!