Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemeoryException when inserting a pdf in PostgreSql

k sreenivas
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?




CREATE TABLE Documents (FileName text, FileData bytea)

Java program:

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

public class SaveFile {

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

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);


Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic