I have a legacy Java based web application which used Oracle 7. Now I'm migrating Oracle 7 to PostgreSQL. We had normal JDBC connectivity with Oracle as we didn't use any framework like Hibernate, iBATIS etc so we created connection, connection pool programmatically and used that. It works fine for Oracle DB.
But as part of migration, when I am changing with PostgreSQL details and trying to connect the DB with my application. At the first DB call only, connection is getting lost and in the logs I am seeing SQL:08003 issue. Since it is web based application so we are creating war and deploying it into apache-tomcat-8.5.50 server. PostgreSQL version is postgresql-42.2.18.jar.
I checked many blogs, but I'm not able to figure it out why this issue is occurring.
Code:
public DBConnection(String dbUrl, String user, char[] pwd) throws SQLException {
String errMsg = "Failed to get connection for login: " + user + " in URL = " + dbUrl;
try {
// Connect to database
mTheConnection = DriverManager.getConnection(dbUrl, user, new String(pwd));
if (mTheConnection == null) {
throw new SQLException (errMsg);
}
mTheConnection.setAutoCommit(false);
} catch (SQLException x) {
throw new SQLException(errMsg);
}
finally{
mTheConnection.close();
}
}