{
defaults = getDefaultProperties();
}
catch (IOException ioe)
{
throw new PSQLException(GT.tr("Error loading default settings from driverconfig.properties"),
PSQLState.UNEXPECTED_ERROR, ioe);
}
// override defaults with provided properties
Properties props = new Properties(defaults);
for (Enumeration e = info.propertyNames(); e.hasMoreElements(); )
{
String propName = (String)e.nextElement();
props.setProperty(propName, info.getProperty(propName));
}
// parse URL and add more properties
if ((props = parseURL(url, props)) == null)
{
logger.debug("Error in url: " + url);
return null;
}
try
{
logger.debug("Connecting with URL: " + url);
// Enforce login timeout, if specified, by running the connection
// attempt in a separate thread. If we hit the timeout without the
// connection completing, we abandon the connection attempt in
// the calling thread, but the separate thread will keep trying.
// Eventually, the separate thread will either fail or complete
// the connection; at that point we clean up the connection if
// we managed to establish one after all. See ConnectThread for
// more details.
long timeout = timeout(props);
if (timeout <= 0)
return makeConnection(url, props);
ConnectThread ct = new ConnectThread(url, props);
new Thread(ct, "PostgreSQL JDBC driver connection thread").start();
return ct.getResult(timeout);
}
catch (PSQLException ex1)
{
logger.debug("Connection error:", ex1);
// re-throw the exception, otherwise it will be caught next, and a
// org.postgresql.unusual error will be returned instead.
throw ex1;
}
catch (java.security.AccessControlException ace)
{
throw new PSQLException(GT.tr("Your security policy has prevented the connection from being attempted. You probably need to grant the connect java.net.SocketPermission to the database server host and port that you wish to connect to."), PSQLState.UNEXPECTED_ERROR, ace);
}
catch (Exception ex2)
{
logger.debug("Unexpected connection error:", ex2);
throw new PSQLException(GT.tr("Something unusual has occured to cause the driver to fail. Please report this exception."),
PSQLState.UNEXPECTED_ERROR, ex2);
}
}