This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
unimplemented or unreasonable request at ps.execute()
File Not found exception..
How to read and write for Image and PDF files
File Not Found Error
how to retrieve images on a jsp page