Thread: SQLException from Postgres JDBC

SQLException from Postgres JDBC

From
"Daniel Gayo Avello"
Date:
Hi, everybody! I've got a problem with Postgres JDBC driver and perhaps somebody could help me. I'm using JDK 1.2.2, JSK 2.0, PostgreSQL 7.0.2 and Apache JServ 1.1.2 and my servlets throw a SQLException when I try to perform a INSERT or DELETE operation...
 
In fact, the operations are done but they don't return any results so a exception is catch by the servlet.
 
Does somebody know the way to avoid this?
 
Thanks in advance, Dani

Re: SQLException from Postgres JDBC

From
Jens Carlberg
Date:
> Daniel Gayo Avello wrote:
> 
> Hi, everybody! I've got a problem with Postgres JDBC driver and
> perhaps somebody could help me. I'm using JDK 1.2.2, JSK 2.0,
> PostgreSQL 7.0.2 and Apache JServ 1.1.2 and my servlets throw a
> SQLException when I try to perform a INSERT or DELETE operation...

Hi!

It is hard to comment when you dont supply any example code that
demonstrates your problem. If you could send a code block in which the
error occurs it would be much easier.

> In fact, the operations are done but they don't return any results so
> a exception is catch by the servlet.

Do this means that the data is inserted/deleted, even though you get an
exception? Then I would guess you handle the returned result in the
wrong way, or something like it.

///Jens Carlberg



Re: SQLException from Postgres JDBC

From
Peter Mount
Date:
On Thu, 28 Sep 2000, Daniel Gayo Avello wrote:

> Hi, everybody! I've got a problem with Postgres JDBC driver and
> perhaps somebody could help me. I'm using JDK 1.2.2, JSK 2.0,
> PostgreSQL 7.0.2 and Apache JServ 1.1.2 and my servlets throw a
> SQLException when I try to perform a INSERT or DELETE operation...
> 
> In fact, the operations are done but they don't return any results so
> a exception is catch by the servlet.
> 
> Does somebody know the way to avoid this?

Which method are you using to perform the INSERT or DELETE?

You should be using executeUpdate() rather than executeQuery() because
executeUpdate() doesn't expect a ResultSet to be returned, and
executeQuery should throw an SQLException when it fails to get one.

An alternative (if you don't know what the query will be) is execute(),
but you then have to handle ResultGet accordingly.

Peter

-- 
Peter T Mount peter@retep.org.uk http://www.retep.org.uk
PostgreSQL JDBC Driver http://www.retep.org.uk/postgres/
Java PDF Generator http://www.retep.org.uk/pdf/




Re: SQLException from Postgres JDBC

From
Michael Stephenson
Date:
> Hi, everybody! I've got a problem with Postgres JDBC driver and
> perhaps somebody could help me. I'm using JDK 1.2.2, JSK 2.0,
> PostgreSQL 7.0.2 and Apache JServ 1.1.2 and my servlets throw a
> SQLException when I try to perform a INSERT or DELETE operation...
> 
> In fact, the operations are done but they don't return any results so
> a exception is catch by the servlet.

Just guessing because your description is so vague..

If you use executeQuery instead of executeUpdate you'll get the exception
postgresql.stat.noresult, which seems to be fit with what you're
describing.

Michael Stephenson



RE: SQLException from Postgres JDBC

From
"Daniel Gayo Avello"
Date:
Thanks both of you (Jens and Peter), yes, I'm using executeQuery and should
be executeUpdate()... Newbie mistakes.

Thanks again. Dani

> > In fact, the operations are done but they don't return any results so
> > a exception is catch by the servlet.
>
> Do this means that the data is inserted/deleted, even though you get an
> exception? Then I would guess you handle the returned result in the
> wrong way, or something like it.
>
> ///Jens Carlberg

> Which method are you using to perform the INSERT or DELETE?
>
> You should be using executeUpdate() rather than executeQuery() because
> executeUpdate() doesn't expect a ResultSet to be returned, and
> executeQuery should throw an SQLException when it fails to get one.
>
> Peter