Skip site navigation (1) Skip section navigation (2)

Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state

From: Lew <noone(at)lewscanon(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state
Date: 2010-11-01 11:25:49
Message-ID: iam83g$kqi$1@news.albasani.net (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

In response to

pgsql-jdbc by date

Next:From: Perepelkin AndrewDate: 2010-11-02 15:08:15
Subject: Invalid Column Length
Previous:From: Sumit PandyaDate: 2010-11-01 09:11:51
Subject: Re: Exception in DriverManager.getConnection creates multiple connections in SYN_SEND state

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group