Understanding Apache Tomcat Connection Pooling

231
July 16, 2017, at 8:53 PM

I am trying to implement Apache Tomcat's built-in JDBC connection pool. But I am confused with many things.

There are 2 methods mentioned in official page to initialize connection pool. One using JNDI lookup and another by java PoolProperty class.

For JNDI lookup, we have to add entry to context.xmlor server.xml and initilize it in the java code. This require database connection details to be hardcoded.

For pool properties, we have to set various connection attributes in PoolProperty class using the datasource object. Does it require instantiating factory? (org.apache.tomcat.jdbc.pool.DataSourceFactory)

Whenever a try using pool properties, I am getting the error:

SEVERE: Unable to create initial connections of pool. java.sql.SQLException: invalid arguments in call at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)

I checked and confirmed all properties are correct. This error goes once I use the xml method. Can someone help me the correct way to configure pooling without xml?

This standalone java code gives me error: PoolProperties p = new PoolProperties();

     String dburl="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=hostname) (PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=shostname2)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=Service)))";
     p.setUrl(dburl);
    p.setDriverClassName("oracle.jdbc.OracleDriver");
    p.setUsername(username);
    p.setPassword(pwd);
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1 from dual");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(600);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
            + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;"
            + "org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer");
    p.setLogValidationErrors(true);   datasource = new org.apache.tomcat.jdbc.pool.DataSource(  );
    datasource.setPoolProperties(p); 

When I add A global Resource to Server.xml as below,it is working.

Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" name="jdbc/database" type="javax.sql.DataSource"/>

Please Help me to understand, what's the correct way of implementation.

READ ALSO
how to disable only cut option on textview android

how to disable only cut option on textview android

I applied this code for Textview Selection

244
Change font of a JFoenix NumberValidator message

Change font of a JFoenix NumberValidator message

I want to change the font of a NumberValidator

182
Error: softValues() is not public in MapMaker; cannot be accessed from outside package

Error: softValues() is not public in MapMaker; cannot be accessed from outside package

Something strange is happeningIve built my Gradle project for 6 times and everything was fine

254
Can objects of a class have access to its private methods?

Can objects of a class have access to its private methods?

I am a beginner with respect to programming in OOPSI was going through the concept of access modifiers in a book and got stuck at a place:

131