pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lew <noone@lewscanon.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state
Date: Mon, 01 Nov 2010 07:25:49 -0400
Message-ID: <iam83g$kqi$1@news.albasani.net> (raw)
In-Reply-To: <000301cb79a4$d1e7fbf0$3902a8c0@elitecore.com>
References: <AANLkTik0rTQ6HhbrY66qpaU+E0jsL9Ra7Lt=vR3FvZja@mail.gmail.com>
	<000301cb79a4$d1e7fbf0$3902a8c0@elitecore.com>

Emanuel Freitas  wrote:
> I'm running a server that receives approximately 300 requests per
> second. For each request I need to do some operations in a database. So,
> when I receive a request i [sic] check if there is any active connection to
> the database and if not i [sic] create one. The code for create the connection
> is something like this:
>
> private Connection initConn() {
>
>   try {
>     Class.forName("org.postgresql.Driver");

You only need to load the driver class once.  Load it in a static initializer 
block.

>   } catch (ClassNotFoundException cnfe) {
>     System.err.println("Error on Driver");

Consider using a logging framework like log4j or java.util.logging.

>     return null;

Consider stopping the application for this particular exception.

>   }
>
>   try {
>
>     Connection db =
>       DriverManager.getConnection("jdbc:postgresql://192.168.1.2:5432/test?loginTimeout=3
>         http://192.168.1.2:5432/test?loginTimeout=3";, "test", "1234");

Consider externalizing the connection details.  Try persistence.xml, 
context.xml or an application server's setup script/screen to create a data 
source.

>     return db;
>
>   } catch (SQLException sqle) {
>     System.err.println("Error on Connection");
>     return null;

You might want to log more details (again, using a logger) to troubleshoot 
this scenario.  One candidate detail is the SQLState.

>   }
> }

-- 
Lew



view thread (3+ messages)

Message-ID: <iam83g$kqi$1@news.albasani.net>
Permalink:  ../iam83g$kqi$1@news.albasani.net/
Also on:    postgresql.org/message-id/iam83g$kqi$1@news.albasani.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: noone@lewscanon.com
  Subject: Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state
  In-Reply-To: <iam83g$kqi$1@news.albasani.net>
  References: <AANLkTik0rTQ6HhbrY66qpaU+E0jsL9Ra7Lt=vR3FvZja@mail.gmail.com> <000301cb79a4$d1e7fbf0$3902a8c0@elitecore.com> <iam83g$kqi$1@news.albasani.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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