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("jdbc:oracle: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)