Trouble with PreparedStatement.setBinaryData or setBytes() - Mailing list pgsql-jdbc

From Alfredo Rico
Subject Trouble with PreparedStatement.setBinaryData or setBytes()
Date
Msg-id 89cc056d05092708171371d8dc@mail.gmail.com
Whole thread Raw
Responses Re: Trouble with PreparedStatement.setBinaryData or setBytes()  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
Hi friends, greetings :-)

First of all, please apologize by my bad english, I don't speak yet very well. I speak spanish.

I'm working in a Java Web development using NetBeans 4.1 + Jakarta FileUploads + PostgreSQL v7.4.7

The situation is as following:

I have a table called 'attachedfiles' in my DB with the follow structre:

CREATE TABLE attachedfiles (
    namefile character varying(100) NOT NULL,    
    content bytea NOT NULL,
    id integer NOT NULL
);

I have Java class with the following code ( very similar to code founded at
http://www.postgresql.org/docs/7.4/static/jdbc-binary-data.html ):

InputStream is = new FileInputStream("/home/alfredo/PostgresqlBook.pdf");
PreparedStatement ps = conn.prepareStatement("INSERT INTO attachedfiles (id, namefile, contentfile) VALUES (?, ?, ?)");
ps.setInt(1,4);
ps.setString(2,"PostgresqlBook.pdf");
ps.setBinaryStream(3, is, is.avalaible() );
ps.executeUpdate();
ps.close();
is.close();


The great and terrible problem is the following:
If input file (pdf, doc, png, txt whatever...) exceed 2 MB
I have the following exception:

javax.servlet.ServletException: La ejecución del
Servlet lanzó una excepción
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
causa raíz
java.lang.OutOfMemoryError: Java heap space

With the following variations in java code even doesn't work:

InputStream is = new FileInputStream("/home/alfredo/PostgresqlBook.pdf");
byte data[] = new bytes[is.avalaible()];
is.read(data);
PreparedStatement ps = conn.prepareStatement("INSERT INTO attachedfiles (id, namefile, contentfile) VALUES (?, ?, ?)");
ps.setInt(1,4);
ps.setString(2,"PostgresqlBook.pdf");
ps.setBytes(3, data );
ps.executeUpdate();
ps.close();
is.close();


Besides, I have increased JVM heap starting Netbeans IDE using the following sentence:

$ ./netbeans -J-Xmx300m

And even don't work...

Could any body help me ? I don't know what to do :-(

Beforehand thank you very much by your help and support.

Kind regards.-
Alfredo Rico.

pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Exception storing ipaddress with JBoss after upgrade to 8.0-312.jdbc3
Next
From: "Kevin Grittner"
Date:
Subject: Re: Trouble with PreparedStatement.setBinaryData or