How to connect do Database with by JNDI name? - java

I am trying to connect to my Database in AppConfig.class :
#PropertySource("classpath:persistence-jndi.properties")
public class AppConfig {
by JNDI name :
#Bean
public DataSource dataSource() throws NamingException {
String pathProperties = environment.getProperty("URL");
return (DataSource) new JndiTemplate().lookup(pathProperties);
}
persistence-jndi.properties : URL = java:comp/env/jdbc/task11dao
web.xml :
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<resource-ref>
<res-ref-name>jdbc/task11dao</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
context.xml ( main - webapp - META-INF - context.xml ) :
<GlobalNamingResources>
<ResourceLink name="jdbc/task11dao" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:3306/task11dao"
username="postgres" password="postgres" maxActive="20" maxIdle="10" maxWait="-1"/>
</GlobalNamingResources>
And when I run my Tomcat Server, I gain an exception ( below you can see the stacktrace ) :
Caused by: org.springframework.jdbc.datasource.init.UncategorizedScriptException: Failed to execute database script; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Data source is closed
at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:59)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.execute(DataSourceInitializer.java:111)
at org.springframework.jdbc.datasource.init.DataSourceInitializer.afterPropertiesSet(DataSourceInitializer.java:96)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
... 33 common frames omitted
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC
Connection; nested exception is java.sql.SQLException: Data source is closed
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
at
org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:47)
... 37 common frames omitted
Caused by: java.sql.SQLException: Data source is closed
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2087)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1563)
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
... 38 common frames omitted
If I connect without JNDI, just :
#Bean
DataSource dataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setUrl(environment.getProperty(URL));
driverManagerDataSource.setUsername(environment.getProperty(USER));
driverManagerDataSource.setPassword(environment.getProperty(PASSWORD));
driverManagerDataSource.setDriverClassName(environment.getProperty(DRIVER));
return driverManagerDataSource;
}
everything is fine.

Related

setClientProgramName in DataSource

In tomcat9 there is a setting in context.xml:
<Resource name="jdbc/db2xx" auth="Container"
type="javax.sql.DataSource" driverClassName="com.ibm.db2.jcc.DB2Driver"
maxTotal="100" maxIdle="30"
maxWaitMillis="-1" username="xx" password="xx"
url="jdbc:db2://xxxx:xxx/dbname;" />
and in Java is :
try {
Class.forName("com.ibm.db2.jcc.DB2SimpleDataSource");
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
com.ibm.db2.jcc.DB2SimpleDataSource ds = (com.ibm.db2.jcc.DB2SimpleDataSource) envContext.lookup("jdbc/db2xx");
ds.setClientProgramName("MyApplication");
conn = ds.getConnection();
}
But I get error :
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to com.ibm.db2.jcc.DB2SimpleDataSource
Do I have to change
org.apache.tomcat.dbcp.dbcp2.BasicDataSource
where ?
The main point is
ds.setClientProgramName("MyApplication");
because I would like to see
MyApplication in APPLICATION_NAME
when I run
SELECT APPLICATION_NAME FROM TABLE(MON_GET_CONNECTION(CAST(NULL AS BIGINT),-2))
or is there any other way ?
If I am using javax.sql.DataSource program works, but I can not use setClientProgramName.
In maven pom :
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.5.7.0</version>
</dependency>
Client info properties support by the IBM Data Server Driver for JDBC and SQLJ.
ApplicationName
ClientAccountingInformation
ClientHostname
ClientUser
These properties mentioned at the link above can't be set with URL.
They can be set with the JDBC 4 method (use db2jcc4.jar, not db2jcc.jar which is JDBC 3 implementation) setClientInfo only like below:
conn = ds.getConnection();
conn.setClientInfo("ApplicationName", "MyApplication");

Module has not been deployed

I am trying to create a web service in a web application on netbeans 8.2 (server-tomcat 8.0.27.0) which can connect to a database on postgres and read a table named "test". i have this code in download.java (web service in a package called serve)
Download.java
#WebService(serviceName = "download")
public class Download {
Connection con=null;
private DataSource getJdbcPostgres() throws NamingException, SQLException {
Context c = new InitialContext();
DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
con=ds.getConnection();
return ds;
}
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) throws ClassNotFoundException, SQLException {
String sql = "select * from test where id="+id;
Class.forName("org.postgresql.Driver");
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
rs.next();
return "";
}
}
here's my context.xml file (in META-INF)
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/service2">
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/postgres"
username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</Context>
and here's web.xml (in WEB-INF):
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>download</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
clean and build command is successful but it doesn't deploy on apache tomcat server
error message (output when I tried to deploy it):
Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/service2
OK - Undeployed application at context path /service2
In-place deployment at D:\NetBeansProjects\service2\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
FAIL - Deployed application at context path /service2 but context failed to start
D:\NetBeansProjects\service2\nbproject\build-impl.xml:1094: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)
when i tried to change server to GlassFish 4.1.1, it says:
Severe: WSSERVLET11: failed to parse runtime descriptor:
com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Caused by: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Severe: Exception while loading the app
Severe: Undeployment failed for context /service2
Severe: Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.apache.catalina.LifecycleException: javax.servlet.ServletException:
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to
parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
I am a newcomer to this field so plz help me if im wrong somewhere or missing something!
I don't know why it happened but I just put try-catch instead of throws and it is getting deployed!
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) {
try {
String sql="select * from test";
Connection conn=myDatasource.getConnection();
PreparedStatement pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
}
catch (SQLException ex) {
Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
}
return "someString";
}
Can anyone suggest why didn't it work earlier? Although my problem is solved yet I'm curious to know what was wrong with 'throws Exception'!
P.S. I'm running it on GlassFish 4.1.1 this time

java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null' for Postgres database

I am using JNDI datasource to connect to Postgres database. This is the code to of my ServletContextListener
public void contextInitialized(ServletContextEvent event) {
try {
// Obtain our environment naming context
Context envCtx = (Context) new InitialContext().lookup("java:comp/env");
// initialize JNDI lookup parameters
DataSource datasource = (DataSource) envCtx.lookup("jdbc/testdb");
ManagerDao.getConn(datasource);
ParticipantDao.getConn(datasource);
EventDao.getConn(datasource);
FacilitiesDao.getConn(datasource);
}
catch (NamingException e) {
e.printStackTrace();
}
}
web.xml of App_path\WebContent\WEB-INF
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/testdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
context.xml
<Resource name="jdbc/testdb"
auth="Container"
type="javax.sql.DataSource"
username="postgres"
password="rules#123"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5433/eventory"
maxActive="20" maxIdle="10"
/>
But I am getting errors while the getConnection() methods are getting called.
java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2167)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2037)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1543)
at com.eventory.dao.FacilitiesDao.getConn(FacilitiesDao.java:26)
at com.eventory.initDB.DBConnListener.contextInitialized(DBConnListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2151)
... 13 more
I have tried the following approaches:
Put the postgresql-42.1.4.jar in the tomcat lib folder.
Put the postgresql-42.1.4.jar in the App_Path\WebContent\WEB-INF\lib
Put the context.xml in the WebContent\META-INF folder
Put the context.xml in the tomcat\conf folder
Nothing seems to work. Is there any other approach that I missed? Please help.

Tomcat DBCP Running out of connections

I'm encountering a ORA-12519, TNS:no appropriate service handler found error when attempting to integrate Tomcat's JDBC Pool into my web application, using Oracle.
I typically see this error appear intermittently, after several minutes of running integration tests against the application.
The configuration I have is:
oracle driver and tomcat-dbcp jars in the tomcat/lib directory
two webapps, both using the same Resources. Configuration done in Spring:
<jee:jndi-lookup id="webDS" jndi-name="jdbc/web"
expected-type="javax.sql.DataSource" />
DataSource Resources defined in conf/context.xml, as follows:
<Resource name="jdbc/web" auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1"
timeBetweenEvictionRunsMillis="30000"
maxActive="20"
maxIdle="10"
minIdle="5"
removeAbandonedTimeout="60"
removeAbandoned="false"
logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
username="${database.user}"
password="${database.password}"
driverClassName="${database.driver}"
url="${database.url}" />
I've tried various suggestions made elsewhere on SO such as increasing or decreasing the maxActive size, but am having no luck thus far. I was previously using c3p0 to manage the pool of connections. With the switch, I'm wondering if there is some additional configuration I need to do that pertains to the closing of connections, because it seems like I'm leaking them.
The stack trace:
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:56)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:159)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:183)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:157)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1881)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1858)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
at org.hibernate.loader.Loader.doQuery(Loader.java:906)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
at org.hibernate.loader.Loader.doList(Loader.java:2550)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366)
at org.hibernate.loader.Loader.list(Loader.java:2361)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:357)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:198)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1230)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268)
... 112 more
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.PooledConnection.reconnect(PooledConnection.java:315)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:803)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:628)
at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:187)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:70)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)
... 132 more
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:399)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
... 146 more
Your validation query (SELECT 1) will not work in Oracle. It has to be select 1 from dual.
Seems that when using a wrong validation query the application is not able to identify healthy connections and and mark all of them as invalid.

Springbatch failing | Could not roll back JDBC transaction

We have several jobs running in springbatch. We restarted the server this morning and afterwards we started having issues with two of the jobs. The BATCH_STEP_EXECUTION table shows the following exit message for each failed execution:
org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:286)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:846)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:823)
at org.springframework.transaction.support.TransactionTemplate.rollbackOnException(TransactionTemplate.java:162)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:135)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:151)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:130)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.ja
This appears to be in relation to the mysql connection the application is making, however I'm not sure what could have caused this as the application was functioning fine before the reboot. Has anyone stumbled across this before?
EDIT
(caused by message that appears in the logs)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
Datasource
javax.sql.DataSource
Connection Pool
Configured in context.xml file with the following format:
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="webapps/appname" mapperContextRootRedirectEnabled="true" mapperDirectoryRedirectEnabled="true" path="/appname" reloadable="false" >
<Resource name="jdbc/springbatchmeta"
auth="Container"
type="javax.sql.DataSource"
username="${jobmeta.username}"
password="${jobmeta.password}"
driverClassName="${mysql.driverClass}"
url="${jobmeta.url}"
initialSize="2"
maxTotal="20"
maxIdle="10"
minIdle="2"/>
<Resource name="jdbc/firstjob"
auth="Container"
type="javax.sql.DataSource"
username="${firstjob.username}"
password="${firstjob.password}"
driverClassName="${mysql.driverClass}"
url="${firstjob.url}"
initialSize="2"
maxTotal="20"
maxIdle="10"
minIdle="2"/>
<Resource name="jdbc/secondjob"
auth="Container"
type="javax.sql.DataSource"
username="${secondjob.username}"
password="${secondjob.password}"
driverClassName="${secondjob.driverClass}"
url="${secondjob.url}"
initialSize="2"
maxTotal="20"
maxIdle="10"
minIdle="2"/>
</Context>
This issue was caused by the wait-timeout option in mysql being set to 60 seconds, as most of the jobs we are running take over a minute to complete.

Categories

Resources