Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemeoryException when inserting a pdf in PostgreSql

 
k sreenivas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic