Tomcat Connection Pool's attribute setting - jdbc

My web application connect DB by Tomcat jdbc pool.
this is my Tomcat context.xml
<Resource
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
name="jdbc/OracleDB"
auth="Container"
type="javax.sql.DataSource"
initialSize="70"
maxActive="100"
maxIdle="30"
minIdle="10"
maxWait="5000"
removeAbandoned="true"
removeAbandonedTimeout="60"
username="XXOO"
password="XXOO"
driverClassName="oracle.jdbc.driver.OracleDriver"
validationQuery="SELECT 'OK'"
testWhileIdle="true"
testOnBorrow="true"
numTestsPerEvictionRun="5"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="60000"
url="jdbc:oracle:thin:#XXOO:testdb"/>
connection timeout will be happened 1min50sec
If I use JDBC to connect DB,it would not happen.
So what's setting do I lose or modify?

Related

Issue in starting Tomcat after migrating to Tomcat 9 from Tomcat 7

I have upgraded Tomcat from 7 to 9. I am getting exception while start up. It is throwing below exception:
oracle.jdbc.xa.client.OracleXADataSource cannot be cast to java.sql.Driver
context.xml has following :
<Resource auth="Container" driverClassName="oracle.jdbc.xa.client.OracleXADataSource"
logAbandoned="true" initialSize="1" maxActive="2" maxIdle="2"
minIdle="2" timeBetweenEvictionRunsMillis="34000"
inEvictableIdleTimeMillis="55000" validationQuery="SELECT 1 FROM DUAL"
validationInterval="34" testOnBorrow="true" removeAbandoned="true"
removeAbandonedTimeout="600" name="jdbc/regionalDS" password="XXX"
type="javax.sql.DataSource" url="jdbc:oracle:thin:#HOSTURL"
username="XXX" />
Please let me know, what changes I need to do.
Two things you can try :
1. Change the type to type="javax.sql.XADataSource"
2. Check that the url is in the form of url="jdbc:oracle:thin:#your_host_name:port_say_1521:service_or_sid"

Apache Tomcat (TomEE)/8.5.6 (7.0.2) Oracle JTS/XA-Datasource Configuration

Has anybody a running example configuration for:
Apache Tomcat (TomEE)/8.5.6 (7.0.2) PLUME
Oracle 11g (ojdbc7.jar)
to match EE/JPA 2.1-Development as near as possible?
Currently i get TomEE's user database, if i try to use my datasource. I think it's caused by the log entry "org.apache.openejb.config.AutoConfig.deploy Found matching datasource: jdbc/jKgvDS but this one is not a JTA datasource", falling back to the last known running datasource. So how can i configure a valid JTA datasource?
server.xml:
<Resource id="jKgvDS" name="jdbc/jKgvDS"
jtaManaged="true"
auth="Container"
type="oracle.jdbc.xa.client.OracleXADataSource"
driverClassName="oracle.jdbc.xa.client.OracleXADataSource"
factory="oracle.jdbc.pool.OracleDataSourceFactory"
url="jdbc:oracle:thin:#db:1521:db"
username="myuser"
password="mypass"
maxActive="20"
maxIdle="30"
maxWait="-1"
validationQuery="SELECT 1 FROM DUAL"
/>
context.xml (tried in conf and app-file)
<ResourceLink global='jdbc/jKgvDS'
name='jdbc/jKgvDS' type="javax.sql.XADatasource"
auth="Container" />
persistence.xml
<persistence-unit name="jKgvPU" transaction-type="JTA">
<jta-data-source>jdbc/jKgvDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<validation-mode>NONE</validation-mode>
<properties>
<property
name="openjpa.jdbc.DBDictionary"
value="org.apache.openjpa.jdbc.sql.OracleDictionary" />
<property
name="openjpa.jdbc.DBDictionary"
value="oracle(maxEmbeddedBlobSize=-1,maxEmbeddedClobSize=-1)" />
<property
name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
Here we go (yeah...):
<Resource id="jKgvDS" name="jdbc/jKgvDS"
jtaManaged="true"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url="jdbc:oracle:thin:#POSDBORA:1521:posdbora"
username="myuser"
password="mypass"
maxActive="20"
maxIdle="30"
maxWait="-1"
validationQuery="SELECT 1 FROM DUAL"
/>
References in web.xml or context.xml are not needed to run.

Data Source from Tomcat to JBoss 6.1

Below is the data source configuration in my Tomcat 7.
Need to convert this into JBoss 6.1, specifically the Eviction & removeAbandoned settings in the standalone.xml file.
Can anyone tell me where I can configure these settings in JBoss?
<Resource connectionCacheName="XXX"
connectionCachingEnabled="true" driverClassName="com.mysql.jdbc.Driver" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
initialSize="10" logAbandoned="true" maxActive="100" maxWait="10000" minEvictableIdleTimeMillis="60000"
minIdle="10" removeAbandoned="true" removeAbandonedTimeout="60" testOnBorrow="true"
testOnReturn="false" testWhileIdle="true" timeBetweenEvictionRunsMillis="30000"
type="javax.sql.DataSource" name="XXXX" url="jdbc:mysql://XXXX"
username="XX" password="XXXX" validationInterval="30000" validationQuery="SELECT
1"/>
According to this Tomcat to JBoss migration guide it should be:
4.x - 5.x - 6.x -> datasource-ds.xml file into JBOSS_HOME/server/[server-name]/deploy
7.x -> datasource-ds.xml file into JBOSS_HOME/standalone/deployments or as a module into JBOSS_HOME/modules

How to set Oracle's fixedString property in Orion Application Server?

I want to set the fixedString=true connection property for the Oracle JDBC driver in the datasource definition in Orion Application Server 2.0.7 (latest stable release).
I've tried the following but didn't work:
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="datasource_name" location="jdbc/datasource_location"
connection-driver="oracle.jdbc.OracleDriver"
username="user" password="pass"
url="jdbc:oracle:thin:#//database_host:1521/XE" >
<property name="fixedString" value="true" />
</data-source>
Note: I've managed to set the property in Tomcat 6.0 this way (using the same Oracle JDBC driver, of course):
<Resource name="jdbc/datasource_name" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="user" password="pass" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#//database_host:1521/XE"
connectionProperties="fixedString=true;"
/>
But I need to set this in Orion. How can I do that?
It is a bug in the oracle application server you have to install OAS 10.1.2.3 has fix for that

Communications link failure due to: java.io.EOFException

My webapp is running on Tomcat 5.5, I declared the datasource in web.xml:
<resource-ref>
<res-ref-name>jdbc/OrdiniWebDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In context.xml (tomcat conf):
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb"
username="[myusername]"
/>
The database is a MySql 5.0.
Everything works well except that sometimes, after several hours of "unuse", at first access I got this Exception:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1956)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2368)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
** END NESTED EXCEPTION **
Last packet sent to the server was 0 ms ago.
com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2579)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2867)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708)
com.mysql.jdbc.Connection.execSQL(Connection.java:3255)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1428)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
com.blasetti.ordiniweb.dao.OrdiniDAO.caricaOrdine(OrdiniDAO.java:263)
...
I need to refresh and it works well again. Any idea? Thanks.
MySQL drops unused connections after a while because it assumes that the other side forgot to close it.
What you need to do is to configure a check that Tomcat should apply before it reuses a pooled connection. To do this, add ?autoReconnect=true&useUnicode=true&characterEncoding=utf8 to the end of the URL and add validationQuery="Select 1" to the Resource element:
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/OrdiniWebDS"
password="[mypassword]"
type="javax.sql.DataSource"
url="jdbc:mysql://[myHost:port]/ordiniweb?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
username="[myusername]"
validationQuery="Select 1"
/>
[EDIT] This page gives more details: Configuring a MySQL Datasource in Apache Tomcat

Resources