deploying spring application to cloud foundry. Cloud foundry has postgres service, trying for jdbc connection using java-cfenv library
application.properties:
database.url = #{cfJdbcEnv.findJdbcService().getJdbcUrl()}
database.username = #{ cfJdbcEnv.findJdbcService().getUsername() }
database.password = #{ cfJdbcEnv.findJdbcService().getPassword() }
database.driverClassName = #{cfJdbcEnv.findJdbcService().getDriverClassName()}
applicationContext.xml
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="localOverride" value="false" />
<property name="locations">
<list>
<value>classpath:application.properties</value>
<value>classpath:application-${spring.profiles.active}.properties</value>
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
pom.xml
<dependency>
<groupId>io.pivotal.cfenv</groupId>
<artifactId>java-cfenv-boot</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.9</version>
</dependency>
Getting error:
Caused by: java.sql.SQLException: No suitable driver found for postgres://postgres:7cpdezVdlt#apa-svc-xxxxxxxxxxxxx.apps.apa.comcast.net:5432/postgres
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:120) ~[spring-jdbc-4.0.3.RELEASE.jar:4.0.3.RELEASE]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:380) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:228) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:171) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:15.01-0500 [APP/PROC/WEB/0] OUT at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1435) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
2021-03-03T17:35:16.00-0500 [APP/PROC/WEB/0] OUT [CONTAINER] org.hibernate.engine.jdbc.spi.SqlExceptionHelper ERROR No suitable driver found for postgres://postgres:7cpdezVdlt#apa-svc-cd1365a3-c6d0-436b-811d-23fc0ec66f0c.apps.apa.comcast.net:5432/postgres
2021-03-03T17:35:16.00-0500 [APP/PROC/WEB/0] OUT [CONTAINER] org.hibernate.engine.jdbc.spi.SqlExceptionHelper WARN SQL Error: 0, SQLState: 08001
DataSource object getting instantiated with below code:
#Bean(name="dataSource")
public DataSource getDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(driverClassName);
String url =
cfEnv.findCredentialsByName("portal-db").getHost();
String username = cfEnv.findCredentialsByName("portal-db").getUsername(); String
password = cfEnv.findCredentialsByName("portal-db").getPassword();
dataSource.setDriverClassName(driverClassName);
dataSource.setUrl("jdbc:postgresql://"+url+":5432/postgres");
dataSource.setUsername(username);
dataSource.setPassword(password);
}
I am not sure why when reading database.url from application.properties file, I am getting error related to wrong url: postgres://postgres:xxxx:5432/postgres
From the error message, it seems to be getting the information. It just does not recognize the JDBC URL that's being provided by your service broker.
I would suggest the following:
Run cf env (or look at the env variables in some other way[1]) and look at VCAP_SERVICES. Look for the property that you are trying to target and confirm that the service broker has a JDBC URL set that starts with jdbc: all JDBC URLs should start with jdbc:.
As a side note, I think the format that's present use to work with the Spring Cloud Connectors, the predecessor library java-cfenv. I believe it would automatically insert the jdbc: part. Your broker may be specifying a JDBC URL that's not strictly a JDBC URL & depending on SCC to correct that.
If you are able to confirm that the URL is just missing the leading jdbc: then you can a.) contact the maker of your service broker (who makes the integration with CF) and ask them to fix this and b.) adjust the way that you're setting the database.url in application.properties to see if you can reformat it in the correct way.
Perhaps something like this (although I didn't test it):
database.url = jdbc:#{cfJdbcEnv.findJdbcService().getJdbcUrl()}
I believe there's a known issue for this, see https://github.com/pivotal-cf/java-cfenv/issues/127 and there is a code commit linked. So it looks like this should eventually start working, once a new release is cut & you upgrade to that release. You can monitor the Github issue for more details. UPDATE this should be fixed in release 2.3.0+.
[1] - Other ways you could look at the env variables: cf ssh into the container & cat /proc/<pid>/environ or dump the env variables through the spring boot actuator /env endpoint.
Related
I am using Spring Batch and connecting to Oracle 12c instance.
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-28040: No matching authentication protocol
And I am getting the below error :
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-28040: No matching authentication protocol
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:619)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:726)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:781)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:145)
at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution(SimpleJobRepository.java:284)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:280)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy1.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:98)
at CustomerFileGenerationMain.main(CustomerFileGenerationMain.java:28)
Caused by: java.sql.SQLException: ORA-28040: No matching authentication protocol
Spring Batch xml file
<bean id="DataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="username" value="MY_OWNER"/>
<property name="url" value="jdbc:oracle:thin:#//localhost:1527/myCloud" />
<property name="password" value="" />
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" >
<property name="dataSource" ref="DataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseType" value="ORACLE" />
</bean>
and pom.xml file -
Only this dependency I used
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
I tried below as well..
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.1</version>
</dependency>
Please guide how to convert below code to XML bean ?
#Bean(name = "DataSource")
public DataSource batchDataSource() throws IOException {
OracleDataSource ds = null;
MCUserInfoFactory userInfoFactory = new MCUserInfoFactory();
try {
MCUserInfo userInfo = userInfoFactory.getMCUserInfo(XXXXLabel);
if (userInfo != null) {
ds = getDataSource(userInfo, edsurl);
}
} catch (Exception e) {
}
return ds;
}
I am using the following version -
/:/oracle/home $ sqlplus / as sysdba
-bash: sqlplus: command not found
/:/oracle/home $ . ~/.profile
/:/oracle/home $ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 28 01:56:56 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
and Real Application Testing options
Check driver file(.jar) version and ORACLE db version you are using is compatible with each other,
usually that causes this issue.
I setup a MessageStore in Spring Integration using JDBC, following there's my configuration:
<bean id="queryProvider" class="org.springframework.integration.jdbc.store.channel.MySqlChannelMessageStoreQueryProvider" />
<!-- JDBC message store configuration -->
<bean id="store" class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
<property name="dataSource" ref="basicDataSource" />
<property name="channelMessageStoreQueryProvider" ref="queryProvider" />
<property name="region" value="TX_TIMEOUT" />
<property name="usingIdCache" value="true" />
</bean>
My underlying DB is Microsoft SQL Server 2012 and when starting up the server I get the following exception:
nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'LIMIT'.
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:664)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:704)
How can I fix this problem?
The best way to implement SqlServerChannelMessageStoreQueryProvider and don't use MySqlChannelMessageStoreQueryProvider, because those RDBMS vendors use different DML.
Feel free to raise a JIRA ticket and even contribute!
I'm not experienced in Java and Spring. I try to write a program that uses JdbcTemplate for Data access. I use DBCP pooling, here it is:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:#192.168.2.7:1521:xe" />
<property name="username" value="manifesto" />
<property name="password" value="manifesto" />
<property name="initialSize" value="2" />
<property name="maxActive" value="4" />
</bean>
My application perform several update operations and then throws an exception:
7053 [SenderThread-0] DEBUG org.springframework.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
Exception in thread "SenderThread-0" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:811)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:867)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:875)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.update(SimpleJdbcTemplate.java:249)
at com.talutek.manifesto.dao.firestorm.dao.spring.MessageItemsTableDaoImpl.update(MessageItemsTableDaoImpl.java:52)
at com.talutek.manifesto.lib.MessageItemMngr.updateItem(MessageItemMngr.java:115)
at com.talutek.manifesto.gw.SenderThread.run(SenderThread.java:42)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 9 more
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
192.168.2.7:1521:xe
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:496)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:465)
at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
... 13 more
When I change pool settings(pool size), the application can run some more times but it then crashes. I think the problem is related to pooling but I couldn't solve it.
Any suggestions?
The same error occurred for me when lots of threads accessed the database simultaneously, and I had a separate DBCP BasicDataSource and a separate Spring JdbcTemplate for each thread.
By making both the BasicDataSource and the JdbcTemplate a singleton shared by all threads, I could avoid this error. This is also what SpringSource recommends.
A google search would have helped: http://www.dba-oracle.com/sf_ora_12519_tns_no_appropriate_service_handler_found.htm
Few suggestions:
Use app server pools if possible
Use c3p0 than DBCP
Use oracle.jdbc.pool.OracleDataSource
I'm trying to get some code I was passed up and running. It appears to use the Hibernate framework. I've gotten past most of the errors tweaking the configuration, but this one has me dead stumped.
It's trying to connect to two databases: gameapp and gamelog. Both exist. It seems to have issues connecting to gamelog, but none connecting to gameapp (later in the init, it connects to and loads other DBs just fine). Below, I've pasted the error and exception stack dump.
I imaging there's something else in the configs, so I've also included the configuration file for that db. I know this is very vague, but I'm hoping some pro can see the stupid mistake I'm missing.
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/gamelog</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="hibernate.jdbc.batch_size">100</property>
<property name="jdbc.fetch_size">1</property>
<property name="hbm2ddl.auto">none</property><!-- update -->
<property name="connection.useUnicode">true</property>
<property name="show_sql">true</property>
<!-- c3p0-configuration -->
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.timeout">30</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
</session-factory>
</hibernate-configuration>
Exception and stack trace:
2010-04-30 17:50:00,411 WARN [org.hibernate.cfg.SettingsFactory] - Could not obtain connection metadata
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at com.database.hibernate.util.HibernateFactory.<init>(Unknown Source)
at com.database.hibernate.util.HibernateUtil.<clinit>(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl.initBreedGoods(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl.access$000(Unknown Source)
at com.server.databaseop.goodOp.GoodOpImpl$1.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:165)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool#ca470 -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 18 more
If you have set C3P0's "checkoutTimeout" property to something other than 0 you might be timing out too quickly (that was my problem, solution: bumped it to 2000 milliseconds from 500).
Alternatively, there's a workaround for this warning:
Set the hibernate.temp.use_jdbc_metadata_defaults property to false.
Found this in http://www.docjar.com/html/api/org/hibernate/cfg/SettingsFactory.java.html, though there may be side effects of not having Hibernate extract JDBC Metadata defaults.
Actually that's not even an authentication error. Is MySQL even running or bound to localhost?
does telnet 127.0.0.1 3306 work?
if so, install the mysql client on the box and try
mysql --user=root --ip=127.0.0.1
and see what happens
Check if you can connect to the gamelog mysql database on the command line with the root user and no password (!). As a side note, I'd recommend to set a password for root and to use a different account to connect to the database from your application, but that's another story.
I have an application that is using Hibernate 3, c3p0, and spring 2.5.6. We have a datasource that is configured to speak with a postgres database. Everything was working great until a firewall was introduced between the application server and the database. We intermittently are getting java.net.SocketTimeoutException: Read Timed Out errors while trying to communicate with the database.
We believe the overhead of the firewall is causing a delayed response from the database. We want to verify this by increasing the thresh hold of how long a query should wait before deemed timed out (if that is even possible). Here is a stacktrace snippet
org.postgresql.util.PSQLException: An I/O error occured while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:218)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1881)
... 35 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:135)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:104)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1166)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
... 44 more
This has nothing to do with Hibernate or C3P0; you're getting a timeout from JDBC driver.
If you're using version 8.4 or higher, try setting socketTimeout to a higher value (or even zero for disabling it) in your connection string.
Try to configure timeout in jdbc properties, like this:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost:5433/yourdb"/>
<property name="username" value="some"/>
<property name="password" value=""/>
<property name="connectionProperties">
<props>
<prop key="socketTimeout">1000000</prop>
</props>
</property>
</bean>
Set for socketTimeout property as much value as required