Unix Technical Forum

PSQLException instead of java.net.SocketException

This is a discussion on PSQLException instead of java.net.SocketException within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> Each time I initiate my servlet, I get an exception. It is thrown when I call the executeQuery method ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:56 PM
Nico
 
Posts: n/a
Default PSQLException instead of java.net.SocketException

Each time I initiate my servlet, I get an exception. It is thrown when I
call the executeQuery method of a statement instance. He throws a
PSQLException. However, when I take a look at the stack trace, it appears to
be a java.net.SocketException was thrown. My best guess is the exception was
catched and a PSQLException was thrown in the catch block. I already have a
catch block for PSQLException which is designed to warn me for SQL syntax
errors, not socket exceptions. So I want to make an additional catch block
for a java.net.SocketException. However I don't know how. Can someone please
help me here?
Reason I want to do this: I can't solve sql syntax errors automatically, but
I can solve socketexceptions automatically by just refreshing the window on
the client side. However if someone can solve the cause in stead of the
catching exception, that's even better.
here is the exception:
An I/O error has occured while flushing the output - Exception:
java.net.SocketException: Socket closed
here is part of the stack trace:
java.net.SocketException: Socket closed
at java.net.SocketOutputStream.socketWrite(SocketOutp utStream.java:99)
at java.net.SocketOutputStream.write(SocketOutputStre am.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:66)
at java.io.BufferedOutputStream.flush(BufferedOutputS tream.java:124)
at org.postgresql.PG_Stream.flush(PG_Stream.java:352)
at org.postgresql.core.QueryExecutor.sendQuery(QueryE xecutor.java:159)
at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:70)
at
org.postgresql.jdbc1.AbstractJdbc1Connection.ExecS QL(AbstractJdbc1Connection.java:505)
at
org.postgresql.jdbc1.AbstractJdbc1Statement.execut e(AbstractJdbc1Statement.java:320)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:48)
at
org.postgresql.jdbc1.AbstractJdbc1Statement.execut eQuery(AbstractJdbc1Statement.java:153)
at
org.postgresql.jdbc1.AbstractJdbc1Statement.execut eQuery(AbstractJdbc1Statement.java:141)
at menus.DBMenu.getQuery(DBMenu.java:705)
at menus.DBMenu.Menupage(DBMenu.java:165)
at menus.DBMenuShow.doGet(DBMenuShow.java:132)

Nico.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2008, 10:56 PM
Dave Cramer
 
Posts: n/a
Default Re: PSQLException instead of java.net.SocketException

Nico,

PSQLException will/should store the cause internally, you should be able
to get the cause out of it and act appropriately.

Dave

Nico wrote:

>Each time I initiate my servlet, I get an exception. It is thrown when I
>call the executeQuery method of a statement instance. He throws a
>PSQLException. However, when I take a look at the stack trace, it appears to
>be a java.net.SocketException was thrown. My best guess is the exception was
>catched and a PSQLException was thrown in the catch block. I already have a
>catch block for PSQLException which is designed to warn me for SQL syntax
>errors, not socket exceptions. So I want to make an additional catch block
>for a java.net.SocketException. However I don't know how. Can someone please
>help me here?
>Reason I want to do this: I can't solve sql syntax errors automatically, but
>I can solve socketexceptions automatically by just refreshing the window on
>the client side. However if someone can solve the cause in stead of the
>catching exception, that's even better.
>here is the exception:
>An I/O error has occured while flushing the output - Exception:
>java.net.SocketException: Socket closed
>here is part of the stack trace:
>java.net.SocketException: Socket closed
> at java.net.SocketOutputStream.socketWrite(SocketOutp utStream.java:99)
> at java.net.SocketOutputStream.write(SocketOutputStre am.java:136)
> at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:66)
> at java.io.BufferedOutputStream.flush(BufferedOutputS tream.java:124)
> at org.postgresql.PG_Stream.flush(PG_Stream.java:352)
> at org.postgresql.core.QueryExecutor.sendQuery(QueryE xecutor.java:159)
> at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:70)
> at
>org.postgresql.jdbc1.AbstractJdbc1Connection.Exec SQL(AbstractJdbc1Connection.java:505)
> at
>org.postgresql.jdbc1.AbstractJdbc1Statement.execu te(AbstractJdbc1Statement.java:320)
> at
>org.postgresql.jdbc2.AbstractJdbc2Statement.execu te(AbstractJdbc2Statement.java:48)
> at
>org.postgresql.jdbc1.AbstractJdbc1Statement.execu teQuery(AbstractJdbc1Statement.java:153)
> at
>org.postgresql.jdbc1.AbstractJdbc1Statement.execu teQuery(AbstractJdbc1Statement.java:141)
> at menus.DBMenu.getQuery(DBMenu.java:705)
> at menus.DBMenu.Menupage(DBMenu.java:165)
> at menus.DBMenuShow.doGet(DBMenuShow.java:132)
>
>Nico.
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
>
>


--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:56 PM
Oliver Jowett
 
Posts: n/a
Default Re: PSQLException instead of java.net.SocketException

Nico wrote:

> My best guess is the exception was
> catched and a PSQLException was thrown in the catch block.


Yes, this is exactly what's happening. In general the driver will throw
a SQLException for all errors, including connection-level problems.

> I already have a
> catch block for PSQLException which is designed to warn me for SQL syntax
> errors, not socket exceptions. So I want to make an additional catch block
> for a java.net.SocketException. However I don't know how. Can someone please
> help me here?


You probably want to look at SQLException.getSQLState(). That gives a
somewhat standardized string that describes the error in more detail.
The driver passes through error codes received from the server directly,
and synthesizes appropriate error codes in some other cases (e.g.
connection failure).

In your case you want to look for all error codes starting with "08"
("Connection Exception"). See
http://www.postgresql.org/docs/curre...-appendix.html for
a list of codes.

You could also do it by looking at the nested exception of the
SQLException, but that's not standard and isn't guaranteed to work; it's
really there to give extra information to a human, not for programmatic
logic.

-O

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:40 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com