wood burning stoves 2.0*
The moose likes JDBC and the fly likes OutOfMemeoryException when inserting a pdf  in PostgreSql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "OutOfMemeoryException when inserting a pdf  in PostgreSql" Watch "OutOfMemeoryException when inserting a pdf  in PostgreSql" New topic
Author

OutOfMemeoryException when inserting a pdf in PostgreSql

k sreenivas
Greenhorn

Joined: Jul 11, 2005
Posts: 2
Hi All,

I am getting OutOfMemeoryException when I am trying to insert a pdf file of size 4.3 MB
into pg database using java. Can one of you suggest me a workaround to fix this problem?

Thanks,
Sreenivas


<hr>
<code>

DDL:
----

CREATE TABLE Documents (FileName text, FileData bytea)



Java program:
-------------

import java.sql.*;
import java.io.*;
import org.postgresql.*;
import org.postgresql.largeobject.*;


public class SaveFile {

public static void main(String[] args) throws Exception {

Class.forName("org.postgresql.Driver");
String url = "jdbcostgresql://myServer/myDB";
Connection conn = DriverManager.getConnection(url,"xxxx","xxxx");

PreparedStatement ps = conn.prepareStatement("INSERT INTO Documents VALUES (?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, (int)file.length());

File file = new File("abc.pdf");
FileInputStream fis = new FileInputStream(file);

ps.close();
fis.close();
}
}

</code>
<hr>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutOfMemeoryException when inserting a pdf in PostgreSql
 
Similar Threads
How to read and write for Image and PDF files
unimplemented or unreasonable request at ps.execute()
File Not Found Error
File Not found exception..
how to retrieve images on a jsp page