*
The moose likes JDBC 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
Bookmark "problem in inserting pdf file" Watch "problem in inserting pdf file" New topic
Author

problem in inserting pdf file

Shyam Sunder
Greenhorn

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.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class PDFConnect
{

public static void main(String args[])
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbcracle:thin:@10.81.7.169:1521:PTS", "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");
ps.setBinaryStream(1,photostream,(int)photo.length());
ps.executeUpdate();
photostream.close();

}

catch(Exception e)
{
e.printStackTrace();
}
}
}


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

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:542)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1311)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:738)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1313)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1232)
at oracle.jdbc.driver.OracleStatement.doExecuteWithBatch(OracleStatement.java:1353)
at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement.java:1760)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1807)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:332)
at PDFConnect.main(PDFConnect.java:24)
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in inserting pdf file