From: Alfredo Rico <alfredorico@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Trouble with PreparedStatement.setBinaryData or setBytes()
Date: Tue, 27 Sep 2005 11:17:36 -0400
Message-ID: <89cc056d05092708171371d8dc@mail.gmail.com> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: alfredorico@gmail.com
Subject: Re: Trouble with PreparedStatement.setBinaryData or setBytes()
In-Reply-To: <89cc056d05092708171371d8dc@mail.gmail.com>
References: <89cc056d05092708171371d8dc@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox