Обсуждение: Trouble with PreparedStatement.setBinaryData or setBytes()

Поиск
Список
Период
Сортировка

Trouble with PreparedStatement.setBinaryData or setBytes()

От
Alfredo Rico
Дата:
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.

Re: Trouble with PreparedStatement.setBinaryData or setBytes()

От
Kris Jurka
Дата:

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


Re: Trouble with PreparedStatement.setBinaryData or setBytes()

От
Alfredo Rico
Дата:
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