Re: NullPointerException while closing connection with

From: Dave Cramer <Dave(at)micro-automation(dot)net>
To: Jani Virta <jani(dot)virta(dot)news(at)kortis(dot)to>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: NullPointerException while closing connection with
Date: 2003-05-08 12:37:15
Message-ID: 1052397435.2756.45.camel@inspiron.cramers
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Well, In general I would recommend the following, which may or may not
solve your problem.

try
{
do sql stuff
}catch ( SQLException )
{
}
finally
{
close connection
}

Because if you throw an exception in your create, or execute the
connection will not be returned to the pool. BTW this applies to
non-pooled connections too!

Dave

On Thu, 2003-05-08 at 04:05, Jani Virta wrote:
> I have multiple threads writing log to db and once a while I get this
> error message, with a result of one connection freezing to "idle in
> transaction" state.
>
> java.lang.NullPointerException
> at
> org.postgresql.jdbc2.optional.PooledConnectionImpl$ConnectionHandler.invoke(PooledConnectionImpl.java:230)
> at $Proxy0.close(Unknown Source)
> at config.logadd(config.java:154)
>
> driver is latest (7.3 jdbc3 build 109)
> jvm is sun j2re 1.4.1_02 with redhat 9
> code I'm using for writing logs. Line 154 is conn.close();
>
> static public void logadd(String s) {
> try {
> Connection conn = datasource.getConnection();
> String insert="INSERT INTO log (time, entry) VALUES ((SELECT
> CURRENT_TIMESTAMP), '"+s+"')";
> Statement logstmt = conn.createStatement();
> logstmt.executeUpdate(insert);
> logstmt.close();
> conn.close();
> } catch (SQLException e) {
> System.out.println("Tried to write : "+s+"\nlog write
> failed. exception "+e);
> }
> }
>
> Any thoughts? Looks like a threading problem since this happens until I
> have max number of connections open and all but one connection in "idle
> in transaction" state.
>
> -jani
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Dave Cramer <Dave(at)micro-automation(dot)net>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message anon permutation 2003-05-11 13:26:11 Strange column naming problem
Previous Message Jani Virta 2003-05-08 08:05:29 NullPointerException while closing connection with connectionpool