From: Adrian Custer <acuster@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: robust handling of initial connection with net interfaces down
Date: Thu, 19 Apr 2007 16:05:45 +0200
Message-ID: <1176991545.18583.4.camel@blackpad> (raw)
hey all,
i'm trying to make our app's connection to postgresql robust. In
testing, I've noticed that if the network interfaces don't exist, the
java instance locks up.
0.setup the server e.g. localhost:5432, user:auser, password:hello
1. Take down your network e.g. ifdown lo
2. run a simple connect to postgresql jdbc such as the file attached
==> the file hangs indefinitely.
Does anyone have a suggestion for preventing this?
Thanks,
adrian
Attachments:JDBCTest.java (text/x-java, 1.6K) download
package com.eofabrik.testing.jdbc;
import java.sql.*;
public class JDBCTest {
public static void main(String[] args) {
System.out.println("Start Test...\n");
//requires postgresql-VERSION.jar on classpath
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String jdbcURL = "jdbc:postgresql";
String host = "localhost";
String port = "5432";
String login = "acuster";
String pass = "hello";
String db = "coredb";
String jdbcPgsqlURL = jdbcURL + "://" + host + ":" + port + "/" + db + ":anythinggoes?";
Connection dbConnection = null;
ResultSet rs = null;
DriverManager.setLoginTimeout(1); //what does this actually do? We still hang on no net.
try{
dbConnection = DriverManager.getConnection(jdbcPgsqlURL, login, pass);
} catch( SQLException ex ){
//System.out.println( "Couldn't get connection!" );
System.out.println(ex.getMessage());
}
if (null != dbConnection){
try {
rs = dbConnection.getMetaData().getCatalogs();
System.out.println("Catalogs are:");
while (rs.next()){
System.out.println(" " + rs.getString(1) );
}
System.out.println();
rs = dbConnection.getMetaData().getSchemas();
System.out.println("Schema are:");
while (rs.next()){
System.out.println(" " + rs.getString(1) );
}
System.out.println();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("\n...End Test. Have a nice day!");
}
}
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: acuster@gmail.com
Subject: Re: robust handling of initial connection with net interfaces down
In-Reply-To: <1176991545.18583.4.camel@blackpad>
References: <1176991545.18583.4.camel@blackpad>
* 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