I'm having an issue that has gone from "annoyance" to "flip the desk".
I have a very basic Spring Boot MVC service with the following Hikari Connection Pool setup:
spring.datasource.username=ME
spring.datasource.password=mypassword
#spring.datasource.url=jdbc:oracle:thin:#SERVICE
spring.datasource.url=jdbc:oracle:thin:#localhost:1521/SERVICE
# need the duplicate because hikari is "special", but it's the spring default
#spring.datasource.jdbc-url=jdbc:oracle:thin:#SERVICE
spring.datasource.jdbc-url=jdbc:oracle:thin:#localhost:1521/SERVICE
# HikariCP settings
spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.hikari.idleTimeout=30000
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.poolName=HikariPool
# leak detection - 30 seconds/30k ms
spring.datasource.hikari.leak-detection-threshold=30000
It seems that a connection is being held. I've tried restarting my Oracle Service and Listener with no luck, and the only solution seems to be to reboot.
Can anyone assist?
Update: I removed Hikari and used this:
spring.datasource.type=org.springframework.jdbc.datasource.SimpleDriverDataSource
I no longer think this is directly related to Hikari.
Edit 2:
Here's the actual "caused by" root exception:
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
(CONNECTION_ID=Z0U0SUlgTNuHsXgisq9YSA==)
at oracle.net.ns.NSProtocolNIO.createRefusePacketException(NSProtocolNIO.java:816) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
at oracle.net.ns.NSProtocolNIO.handleConnectPacketResponse(NSProtocolNIO.java:396) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:207) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:350) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:2372) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:657) ~[ojdbc8-21.5.0.0.jar:21.5.0.0.0]
... 85 common frames omitted
That particular CONNECTION_ID is randomized and different each time.
We are migrating Tomcat6, java 6 and Oracle 10g web-applications to Tomcat 8, Java 8 and Oracle 10g. Our applications working fine after migrated, but initial connections (initialSize="5") available in connection pool not released after Tomcat shut down. When second time starting tomcat, its creating 5 more initial connections to pool. I am using below resource configuration in server.xml
<Resource name="TestAppDataSource"
auth="Container"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
initialSize="5"
maxActive="40"
maxIdle="40"
minIdle="5"
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="30000"
maxWait="10000"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="false"
validationQuery="SELECT 1 from dual"
validationInterval="30000"
logAbandoned="true"
removeAbandonedTimeout="30"
removeAbandonedOnBorrow="true"
removeAbandonedOnMaintenance="true"
suspectTimeout="300"
maxAge="60000"
url="jdbc:oracle:thin:#//IP_ADDRESS:1521/SCHEMA_NAME"
username="USER_NAME"
password="PASSWORD" />
And below resource link configuration in application META_INF/context.xml
<ResourceLink
name="APP_TEST"
global="TestAppDataSource"
type="javax.sql.DataSource"
/>
I am using ojdbc7.jar for oracle driver. Please help whether i missed any configuration..
try with the follow option:
removeAbandoned = true
(boolean) Flag to remove abandoned connections if they exceed the
removeAbandonedTimeout. If set to true a connection is considered
abandoned and eligible for removal if it has been in use longer than
the removeAbandonedTimeout Setting this to true can recover db
connections from applications that fail to close a connection. See
also logAbandoned The default value is false.
Tomcat now use JDBC Connection Pool org.apache.tomcat.jdbc.pool that is a replacement or an alternative to the Apache Commons DBCP connection pool.
removeAbandoned is a option for JDBC Connection Pool
https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html
You have to add closeMethod="close" to your JDBC resource in context.xml. That way, Tomcat properly releases pending connections to the database.
Nitpick: when tomcat is shut down, the JVM is shut down, hence all of its resources are "released" too, and there is no more connection pool - what you meant is that the connections are not properly being shut down, so the DB is not being notified that they're closed, and hence the sessions there are not being ended. This is either because the pool is not getting a shutdown command, or because something else is hanging in tomcat during shutdown and hence it's not getting to the point of shutting down the pool, being force-killed by the shutdown script after a wait timeout has expired. You can take thread dumps during shutdown to see what it's waiting on, and look at catalina.out for messages about leaked threads (...has started a thread ... that's not been shut down ...). It is a common problem that webapps will launch long-running threads without daemonizing them - such webapps need to implement a ServletContextListener that will stop this thread/resource when the ServletContext is stopped.
I am getting the following error below
Unexpected error
org.springframework.transaction.CannotCreateTransactionException:
**CannotCreateTransactionException:** Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBC
Exception: Could not open connection
Here is the scenario in which it occurs :
I have recently moved some table from mysql to mongo. The code is written in such a way that either data would be taken from mongo/mysql.
The code is written in a method block which is annotated with #Transactional provided by spring framework.
There is hibernate layer which is using transaction provided by spring. c3p0 is the connection pool.
The parameter of connection pool is
hibernate.c3p0.min_size=5
hibernate.c3p0.timeout=1200
hibernate.c3p0.max_size=35
hibernate.c3p0.max_statements=50
The problem comes when we try to pull the data from mongo.Looks like the transaction is not getting closed because of mongo operation.The database connection is not getting released .It reaches the max size defined in the pool.
Tried the query in DB to find out the connection
show status like '%onn%';
Any suggestion to resolve this would really help.
Thanks
I am using Spring JdbcTemplate class for performing database operations. My server is Tomcat 7.
When I click the button of my application to perform some DB operations I get the following error
org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [XXXXX (my query) ];
IO Error: Socket read timed out; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out
Strange Behaviour:- This is happening only for the very first time. When I click the button next time everything is fine.
I even tried accessing the DB directly from toad and I am not getting any connection time out there.
DB Properties in context.xml:-
Resource name="jdbc/dsStaloneTelefoni"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:#someIP:XXXXX"
username="XXXX"
password="XXXXXXXXXX"
testOnBorrow="true"
testOnReturn="true"
validationQuery="select 1 from dual"
maxActive="20"
maxIdle="30"
maxWait="-1"/>
Please help.
I have a Dynamic Web Project in Eclipse and is trying to connect through JDBC to Oracle 11g Release 2 Express Edition. But I am getting the error with the following message :
Could not connect to Oracle 11g XE Conn.
Error creating SQL Model Connection connection to Oracle 11g XE Conn. (Error: IO Error: The Network Adapter could not establish the connection)
IO Error: The Network Adapter could not establish the connection
Error creating JDBC Connection connection to Oracle 11g XE Conn. (Error: IO Error: The Network Adapter could not establish the connection)
IO Error: The Network Adapter could not establish the connection
To add, since I am using Apache Tomcat 6.0.35, I have added the Resource and ResourceParams (for the database that I am trying to access) in the server.xml file of
\conf.
<Resource name="jdbc/FlightDB" scope="Shareable" type="javax.sql.DataSource"
auth="Container" description="Home Oracle 11g Express Edition"/>
<ResourceParams name="jdbc/FlightDB">
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:#server:1521:flightDB</value>
</parameter>
<parameter>
<name>username</name>
<value>system</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
</ResourceParams>
Also, I have added the resource-ref element in web.xml of my current web application.
<resource-ref>
<res-ref-name>jdbc/FlightDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
But it is no help as the problem recurs.
Any help will be greatly appreciated. Look forward to replies.
Thanks,
Somnath
Try following url
jdbc:oracle:thin:#localhost:1521:xe
Last part is SID of server, not database name. Database (or Schema) name is determined by user name during log in. So if your database name is flightDB then there is also user called flightDB. Also check that user has sufficient privileges.