When I am trying to log-in to my application I am getting the following error message :
Mar 13, 2014 11:56:56 AM org.apache.catalina.realm.DataSourceRealm getPassword
SEVERE: Exception retrieving password for username
some configuration:
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
global="jdbc/ARAIDB"
maxActive="100"
maxIdle="30"
maxWait="10000"
name="jdbc/ARAIDB"
password=""
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/arai_prod"
username="root"/>
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/ARAIDB"
roleNameCol="role_name"
userCredCol="password"
userNameCol="account_name"
userRoleTable="accounts_role"
userTable="active_account"/>
Thanks in advance
Related
Here is my tomcat context.xml file with my config for MySql (1 master / 1 read replica).
<Resource auth="Container"
driverClassName="com.mysql.jdbc.ReplicationDriver"
defaultAutoCommit="false"
initialSize="3"
logAbandoned="false"
maxActive="200"
maxIdle="10"
maxWait="10000"
name="jdbc/powerptc"
removeAbandoned="true"
testOnBorrow="true"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="username"
password="password"
url="jdbc:mysql:replication://localhost:3306,2.2.2.222:3306/mydb?autoReconnect=true&allowSlaveDownConnections=true&readFromMasterWhenNoSlaves=true&connectTimeout=15000&socketTimeout=15000"
validationQuery="/* ping */ SELECT 1"/>
My issue is when the slave (2.2.2.222) is down, I tomcat won't start. I was hoping to configure it so that tomcat would still start with a slave down, and just use the master for all queries is this possible?
We are getting java.sql.SQLException: Connection has already been closed. exception intermittently while performing a transaction. We are using tomcat 7.X and below is the configuration.
<Context docBase="ROOT" reloadable="true" antiJARLocking="true">
<Resource
name="jdbc/DS"
auth="Container"
type="javax.sql.DataSource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://XXXXXXX"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="XXXXXX"
password="XXXXXX"
maxActive="20"
maxIdle="3"
minIdle="3"
maxWait="10000"
removeAbandoned="true"/>
</Context>
Probably we are missing some configuration or property here that is causing the issue.
Please suggest a way fix this issue or help to find out the root cause.
Following configuration worked for me
<Context context="ROOT" debug="0" reloadable="false" useHttpOnly="true" cacheMaxSize="40960" cacheTTL="60000" cachingAllowed="true" antiJARLocking="true">
<Resource name="XYZ" auth="Container"
description="Exchange DB Connection"
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
dataSource.serverName="XXXXX"
dataSource.databaseName="XXXX"
dataSource.portNumber="XXXX"
dataSource.user="xyz"
dataSource.password="xyz"
maximumPoolSize="20"
minimumIdle="5"
connectionTimeout="300000"
factory="com.zaxxer.hikari.HikariJNDIFactory"
registerMbeans="true"
type="javax.sql.DataSource" />
The key value here is connectionTimeout.
The factory which you are currently using has a default timeout, after that it forces session to close.
The connection timeout value above worked for me , for your application scenarios you'll have to experiment a bit to get the right value.
add below value:
removeAbandonedTimeout="600"
I have a webapp deployed in Tomcat 7. There I cave configured my database pool as given below.
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
<Resource type="javax.sql.DataSource"
name="jdbc/TEST"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull"
username="test"
password="test"
initialSize="10"
maxActive="100"
maxIdle="50"
minIdle="10"/>
This configuration works fine.But I want to configure my database pool to reconnect data database server automatically when a database server down for sometime and started again.
Try to add
?autoReconnect=true
in your url.
I found an answer for this problem. Below configuration done the job.
<Resource type="javax.sql.DataSource"
name="jdbc/TEST"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull"
validationQuery="select 1"
validationInterval="30000"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
username="test"
password="test"
initialSize="10"
maxActive="100"
maxIdle="50"
minIdle="10"/>
If I deploy a web app to Tomcat, and have code like this:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/myDB");
How can I specify for this DataSource to be a PoolingDataSource? How do I configure the pool (GenericObjectPool) to inject the PoolingDataSource with?
Or, is this the default behavior of Tomcat's JNDI implementation? Thanks in advance!
Just configure the connection pool settings (maxActive, maxWait, maxIdle, ...).
Tomcat comes with the apache commons-dbcp library. It is repackaged as $CATALINA_HOME/lib/tomcat-dbcp.jar.
Take a look at the tomcat doc for details: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Database_Connection_Pool_%28DBCP%29_Configurations
<Context>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
</Context>
The JDBC Connection Pool org.apache.tomcat.jdbc.pool
is a replacement or an alternative to the commons-dbcp
connection pool.
Add to the server.xml file in the GlobalNamingResources section something like the next:
<Resource name="jdbc/TestDB"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
maxActive="100"
minIdle="10"
maxWait="10000"
initialSize="10"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="root"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mysql"/>
Add the JDBC driver JAR into the Tomcat lib directory.
Add in your context.xml:
<ResourceLink global="jdbc/TestDB" name="jdbc/TestDB"
type="javax.sql.DataSource"/>
See more in The Tomcat JDBC Connection Pool.
I am using JNDI with Tomcat6 to manage Mysql connections, my Catalina/domain.com/ROOT.xml has:
<Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource"
username="db1" password="somepass" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db?autoReconnect=true" maxActive="15" maxIdle="3"
maxWait="5000" removeAbandoned="true" removeAbandonedTimeout="20" />
I though autoReconnect will do the job reconnecting to database but it does not, after about 8 hours of inactivity my app spits out lost connection to database errors. Any ideas?
Thanks, Fedor
Dont use autoReconnect. There are problems with it and it's been deprecated. For example, you could have a disconnect/reconnect event happen while a thread is using the connection. I would instead have your connection pool test connections with testOnBorrow before passing them to the app. Here is an example:
<Resource name="jdbc/db"
auth="Container"
type="javax.sql.DataSource"
username="db1"
password="somepass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/db"
maxActive="15"
maxIdle="3"
maxWait="5000"
removeAbandoned="true"
removeAbandonedTimeout="20"
logAbandoned="true"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
validationQuery="select 1"
minEvictableIdleTimeMillis="3600000"
timeBetweenEvictionRunsMillis="1800000"
numTestsPerEvictionRun="10"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
/>