Skip site navigation (1) Skip section navigation (2)

Trouble with PreparedStatement.setBinaryData or setBytes()

From: Alfredo Rico <alfredorico(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Trouble with PreparedStatement.setBinaryData or setBytes()
Date: 2005-09-27 15:17:36
Message-ID: 89cc056d05092708171371d8dc@mail.gmail.com (view raw or flat)
Thread:
Lists: 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.

Responses

pgsql-jdbc by date

Next:From: Kevin GrittnerDate: 2005-09-27 15:41:48
Subject: Re: Trouble with PreparedStatement.setBinaryData or
Previous:From: Dave CramerDate: 2005-09-27 13:48:49
Subject: Re: Exception storing ipaddress with JBoss after upgrade to 8.0-312.jdbc3

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group