File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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