How to retieve binary data (bytea) without problem ?

From: Alfredo Rico <alfredorico(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Cc: Kris Jurka <books(at)ejurka(dot)com>
Subject: How to retieve binary data (bytea) without problem ?
Date: 2005-09-28 20:27:19
Message-ID: 89cc056d050928132714e17730@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi friends, greetings :-)

I'm using PostgreSQL v7.4.7 with JDBC driver version 8.0 Build 312 in a Java
Web Deveploment.

I have a table named 'attachedfiles' in which there is a column used to
store binary data (bytea type) (pdf's files, doc, png, jpg, what ever...).

I have stored, without troubles, binary data reaching 30 MB.

To retrieve the binary data I'm using the following Java code:

PreparedStatement ps = this.con.prepareStatement("SELECT contentfile from
attachedfiles where filename = ? ", ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
ps.setString(1,"UsingJDBC.pdf");
bytes filebinary[] = null;
ResultSet rs = ps.executeQuery();
if (rs != null)
{
while (rs.next()) //Only one row
{
filebinary = rs.getBytes(1); //Obtain the file...
}
rs.close();
}
ps.close();

Problem:
If the binary data that I want to retrieve, is up to 12 MB, I obtain a
java.lang.OutOfMemoryError: Java Heap Space.

I'm using NetBeans 4.1 and a I have increased the JVM heap size uing the
following comand at momento to start Netbeans IDE

$ ./netbeans -J-Xmx300m

but this don't work.

How could I overcome this error ?

Thanks in advance by your help and support.

Kind Regards.-
Alfredo Rico.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Pedro Mendes 2005-09-28 22:11:11 Problem getting a connection with Postgres 8.0.3
Previous Message Oliver Jowett 2005-09-28 00:20:19 Re: Exception storing ipaddress with JBoss after upgrade to