Tomcat SQL doesn't refresh - java

I have a Java RESTful Webservice running on Tomcat7 in Ubuntu.
When I change fields in the Database the Webservice returns the old values.
When i restart the service, it returns the new values.
this is my Context.xml:
<Context>
<Resource name="jdbc/schischule"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://IP:3306/Skischul_DB"
username="admin"
password="pwd"
maxActive="20"
maxIdle="30"
maxWait="-1"
/>
</Context>
Has anyone an idea why Tomcat doesn't refresh the data?
THX

Related

Problems with Tomcat8 using connection pooling to OracleDB

We have an application provided by a 3rd party vendor that runs on Tomcat 8 and JDK 8 to an Oracle 12 DB with ojdbc7.jar & xdb6.jar driver. The application works, but is slower than expected. When investigating it appears the application is configured to use connection pooling, but it appears the application is creating new connections per query, and not using any of the initially created connections to the Database.
Unfortunately, I don't have access to the code of the 3rd party app. But, hoping for an idea on what I am missing in the Tomcat setting to have pooling work.
I've tried going through Apache's documentation for the older Oracle connections, and trying other options found on the web.
<Resource name="jdbc/DataSource" auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:XE"
username="myProxyUser" password="myPassword"
initialSize="5" maxTotal="100" maxIdle="-1"
maxWaitMillis="30000"
validationQuery="select 1 from dual"
testOnBorrow="true"
accessToUnderlyingConnectionAllowed = "true"
connectionProperties="defaultRowPrefetch=100"
removeAbandoned = "true"
removeAbandonedTimeout = "30"/>
You can check tomcat docs, mainly use factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
example on how to configure a resource for JNDI lookups
<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"/>
you can specify pooling by defining type and factory
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"

Docker external database mapping

I have cloned 'knowage' BI tool to my local cetnos 7 server and successfully ran the docker containers. My challenge is in connecting to a mariadb database that is in the Host machine! I want the knowage container to access that database in the Host machine. below is my server.xml file for the connection configs used by knowage..
<GlobalNamingResources>
<Resource name="jdbc/datasource" auth="Container"
type="javax.sql.DataSource"
driverClassName="org.mariadb.jdbc.Driver"
url="jdbc:mariadb://ip-addr:3306/datasource"
username="beberu"
password="***********"
maxActive="20" maxIdle="10"
maxWait="-1"/>
<!-- KNOWAGE -->
<Resource auth="Container" driverClassName="org.mariadb.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/knowage" type="javax.sql.DataSource" url="jdbc:mysql://1$
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="$
<ResourceLink global="jdbc/datasource" name="jdbc/datasource" type="javax.sql.DataSource"/>
</GlobalNamingResources>
You have to use the ip address of the docker0 interface in the place of 10.66.110.7.
You can get the ip address using this command.
$ ip addr show docker0
In the result use the ip after, inet.

Tomcat not executing the correct realm

I am working on a tomcat 7 webapp that I recently inherited. We are working on migrating from Tomcat 5.5.
The webapp uses a tomcat realm to handle a combination of ldap/sql authentication.
When I define my context.xml as follows
<Context docBase="*******" reloadable="false">
<Realm className="com.******.tomcat.auth.LdapSqlRealm"
****
/>
<Resource name="jdbc/*****"
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="60000"
maxActive="15"
maxIdle="15"
maxWait="30000"
initialSize="10"
removeAbandonedTimeout="60"
removeAbandoned="true"
logAbandoned="true"
minEvictableIdleTimeMillis="60000"
numTestsPerEvictionRun="2"
jmxEnabled="true"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="*****"
password="*****"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="*****"
/></Context>
I can see my realm initializing in the logs, but when I go to authenticate (using basic) it doesn't use my realm.
If I define the realm in the server.xml file it works just fine.
Any thoughts on why I can't define it in the context.xml.
Our context.xml file is actually located in cont/Catalina/localhost/*****.xml
I have tried starting from scratch with simple realms, or extensions of RealmBase and they all do the same thing.
Thanks,
Travis
Turns out that I had an extra <Context /> tag in my <Host /> tag in my server.xml which was messing up my context.xml file.
Little Santi tipped me off by suggesting a vanilla build of tomcat, which I didn't end up doing, but I did a compare of server.xml from the two and spotted the issue right away. Wish I had thought of it sooner.

Naming error while using multiple connection pools in a Tomcat 8 application

I have an application that uses the built-in Tomcat connection pool, and for the most part it works. A problem arises when I'm trying to use another pool to get a different set of connection from the same database, but from a different username/password (It's an oracle database that uses 2 usernames to access different namespaces of tables and function).
The first pool is accepted, but for the second one, I'm getting this error
15:09:47.157 [http-nio-8081-exec-5] ERROR com.applicationname.providers.ConnectionManager - NamingException in MyDataSource
javax.naming.NameNotFoundException: Name [appdb_two] is not bound in this Context. Unable to find [appdb_two].
at org.apache.naming.NamingContext.lookup(NamingContext.java:818) ~[catalina.jar:8.0.15]
Here is my configuration:
server.xml
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users-->
<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 name="jdbc/appdb_two"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>
<Resource name="jdbc/appdb_one"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>
</GlobalNamingResources>
context.xml
<ResourceLink name="jdbc/appdb_two"
auth="Container"
username="DBONE"
password="xxxx"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:#xx.xxx.xxx.xxx:1521:XE"
initialSize="20"
maxActive="50"
maxIdle="20"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>
<ResourceLink name="jdbc/appdb_one"
auth="Container"
username="DBTWO"
password="xxxx"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:#xx.xxx.xxx.xxx:1521:XE"
initialSize="20"
maxActive="50"
maxIdle="20"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>
...
I think you're looking up the second datasource via name "appdb_two", but should be using "jdbc/appdb_two" - it's hard to see from the stacktrace alone, code for lookup would be helpful.
Also check that your web.xml has references to both data sources (<resource-ref> elements).

Eclipse Tomcat creating 3 duplicate JNDI connection pools

On one developer workstation running Eclipse Helios SR2, Windows 7 and Tomcat 6.0.32 we have a very strange case of duplicate JNDI connection pools
Running tomcat from Eclipse
server.xml
>
<Context docBase="path to web app" path="/ds-web" reloadable="true">
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
</Context>
When start server, on the console we see the following 3 times in a row
AbandonedObjectPool is used
(org.apache.commons.dbcp.AbandonedObjectPool#11aa58b)
LogAbandoned: true
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
Application then fails to find the JNDI resource
If we remove the <Resource> in server.xml, then the console shows no connection pool is created at all
On another developer machine with the same hardware and OS we do not have this problem
Any ideas?
Thanks
Marc
My suggestion, Copy the whole <Context> from server.xml and create a blank context.xml inside your web application META-INF folder and paste the <Context> copied from server.xml there.
Restart your application and see if this works.
We re-installed postgresql on the machine and the problem got solved somehow.
We're thinking something in the original postgresql config had been messed up and tomcat was failing to connect to the BD somehow. I guess tomcat was simply "trying 3 times", thus the triple output.
Another unsolved mystery...
move
<Resource
name="jdbc/ds"
username="ds"
password="pass"
type="javax.sql.DataSource"
url="jdbc:postgresql://localhost:5432/ds"
auth="Container"
driverClassName="org.postgresql.Driver"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
logAbandoned="true"
maxActive="30"
maxIdle="10"
maxWait="1000"
removeAbandoned="true"
removeAbandonedTimeout="60"
validationQuery="SELECT 1"
testOnBorrow="true"
testOnReturn="true"/>
to server.xml namely the
<GlobalNamingResources>
element
in your conf/context.xml file you would instead specify
<ContextLink name="jdbc/ds" global="jdbc/ds"/>
and this way, the three contexts will share the same pool.

Categories