Tuesday, October 13, 2015

Resolve DBCP database connection failure when connecting to RAC oracle database server


How to resolve the database connection issue when connecting to oracle RAC cluster servers.

Our application used DBCP (Apache Common) jar with the spring - hibernate framework to establish connection pool.

When we connected to RAC server we got the below exception.

database connection check SQL Exception : Io exception: Connection refused(DESCRIPTION=(ERR=1153)(VSNNUM=0)(ERROR_STACK=(ERROR=(CODE=1153)(EMFI=4)(ARGS='(DESCRIPTION=(address=(protocol=tcp)(host=somehost.web.com)(port=1111))(CONNECT_DATA=(CID=(PROGRAM=)(HOST=__jdbc__)(USER=))null))'))(ERROR=(CODE=303)(EMFI=1))))

After analyzing i noticed that i was using classes12.jar, which needs to be upgraded to a new version of ojdbc7.jar.

Resolution upgrade to newer version of ojdbc7.jar.


Also the RAC connection was to be made using the Service name not the SID which is a standard for this RAC cluster architecture.

Hint one the url string is 

jdbc:oracle:thin:@//somehost.web.com:portnumber/service name.

There are other ways to declare the url string which is similar to the tnsora oracle client string.

Sample standalone code for testing:

import java.sql.Connection;
import org.apache.commons.dbcp.BasicDataSource;
public class DBConnectTest {
public static void main(String args[]){
String driver = "oracle.jdbc.driver.OracleDriver";
String url ="jdbc:oracle:thin:@//somehost.web.com:portnumber/servicename";
String username = "username";
String password ="password";

 try{
   org.apache.commons.dbcp.BasicDataSource dataSource = new BasicDataSource();
   dataSource.setDriverClassName(driver);
   dataSource.setUrl(url);
   dataSource.setUsername(username);
   dataSource.setPassword(password);
   Connection basicDataSourceCon = dataSource.getConnection();
   System.out.println("\n basicDataSourceCon ::"+basicDataSourceCon);
   System.out.println("Connected to oracle DB");
    }catch(Exception e){
   System.out.println("DB Connection Exception");
   e.printStackTrace(); }
}
}

we need the following jars.
commons-dbcp-1.2.2.jar (any new version x.x.x)
commons-logging-1.1.1.jar (any new version x.x.x)
commons-pool-1.4.jar (any new version x.x)


Refer the below link too.
https://community.oracle.com/thread/358849?start=0&tstart=0

No comments:

Post a Comment