pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Trouble with PreparedStatement.setBinaryData or setBytes()
4+ messages / 3 participants
[nested] [flat]

* Trouble with PreparedStatement.setBinaryData or setBytes()
@ 2005-09-27 15:17 Alfredo Rico <alfredorico@gmail.com>
  2005-09-27 18:16 ` Re: Trouble with PreparedStatement.setBinaryData or setBytes() Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Alfredo Rico @ 2005-09-27 15:17 UTC (permalink / raw)
  To: 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.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Trouble with PreparedStatement.setBinaryData or setBytes()
  2005-09-27 15:17 Trouble with PreparedStatement.setBinaryData or setBytes() Alfredo Rico <alfredorico@gmail.com>
@ 2005-09-27 18:16 ` Kris Jurka <books@ejurka.com>
  2005-09-27 18:53   ` Re: Trouble with PreparedStatement.setBinaryData or setBytes() Alfredo Rico <alfredorico@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Kris Jurka @ 2005-09-27 18:16 UTC (permalink / raw)
  To: Alfredo Rico <alfredorico@gmail.com>; +Cc: pgsql-jdbc



On Tue, 27 Sep 2005, Alfredo Rico wrote:

> If input file (pdf, doc, png, txt whatever...) exceed 2 MB
> I have the following exception:
>
> java.lang.OutOfMemoryError: Java heap space
>

You should try upgrading to the 8.0 driver which does a much better job of 
memory management and streaming data to the server.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Trouble with PreparedStatement.setBinaryData or setBytes()
  2005-09-27 15:17 Trouble with PreparedStatement.setBinaryData or setBytes() Alfredo Rico <alfredorico@gmail.com>
  2005-09-27 18:16 ` Re: Trouble with PreparedStatement.setBinaryData or setBytes() Kris Jurka <books@ejurka.com>
@ 2005-09-27 18:53   ` Alfredo Rico <alfredorico@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Alfredo Rico @ 2005-09-27 18:53 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Kris,
Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank
you Thank you Thank you Thank you Thank you Thank you Thank you Thank you
Thank you

Thank you Kris... That's was the solution to all problem. Using JDBC driver
for PostgreSQL v.8.0 was the solution, I was using JDBC version 7.4 Build
216 becuase I'm working with PostgreSQL v7.4.7.

Kris, anew thank you so much...

Warm Regards.-
Alfredo Rico.-

On 9/27/05, Kris Jurka <books@ejurka.com> wrote:
>
>
>
> On Tue, 27 Sep 2005, Alfredo Rico wrote:
>
> > If input file (pdf, doc, png, txt whatever...) exceed 2 MB
> > I have the following exception:
> >
> > java.lang.OutOfMemoryError: Java heap space
> >
>
> You should try upgrading to the 8.0 driver which does a much better job of
> memory management and streaming data to the server.
>
> Kris Jurka
>
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Trouble with PreparedStatement.setBinaryData or
@ 2005-09-27 15:41 Kevin Grittner <Kevin.Grittner@wicourts.gov>
  0 siblings, 0 replies; 4+ messages in thread

From: Kevin Grittner @ 2005-09-27 15:41 UTC (permalink / raw)
  To: alfredorico@gmail.com; pgsql-jdbc

The memory setting for your IDE isn't necessarily what is used
for processes run from the IDE.  I don't use NetBeans, but in
Eclipse there is a place to define your launch parameters; you
should look for something similar in NetBeans and set use the
-Xmx setting there.
 
 
>>> Alfredo Rico <alfredorico@gmail.com> 09/27/05 10:17 AM >>>

. . .
 
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

. . .

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

$ ./netbeans -J-Xmx300m

And even don't work...




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-09-27 18:53 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-27 15:17 Trouble with PreparedStatement.setBinaryData or setBytes() Alfredo Rico <alfredorico@gmail.com>
2005-09-27 18:16 ` Kris Jurka <books@ejurka.com>
2005-09-27 18:53   ` Alfredo Rico <alfredorico@gmail.com>
2005-09-27 15:41 Re: Trouble with PreparedStatement.setBinaryData or Kevin Grittner <Kevin.Grittner@wicourts.gov>

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