Spring Tomcat JDBC Connection Pooling - How to recover when database goes offline - java

I am building an app using Spring Boot with MSSQL. For connection pooling I am using Tomcat JDBC.
My question what happens to the connection pool when a database is taken offline for a few minutes and what is the best way to recover from this database going offline.
I have tried the following tomcat connection pool configuration and when the database was taken offline and then brought online new connections were not established. I keep gettin the exception com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Tomcat JDBC Configuration:
primary.datasource.tomcat.testWhileIdle=true
primary.datasource.validationQuery=SELECT 1
primary.datasource.validationInterval=34000
primary.datasource.initial-size=10
primary.datasource.max-active=50
primary.datasource.max-idle=20
primary.datasource.min-idle=10
primary.datasource.timeBetweenEvictionRunsMillis=34000
primary.datasource.minEvictableIdleTimeMillis=55000
primary.datasource.removeAbandoned=true
primary.datasource.removeAbandonedTimeout=55000
Please note that I have two datasources configured

Related

Opened LDAP Connections from connection pool after server restart (UnboundId)

I'm using UnboundID LDAP SDK for Java to query Active Directory using LDAP.
I'm creating the connection every time now so I'd like to change my code to use connections pool. I've found some examples how to create a connections pool, how to get and return the connection (link). I plan to do so using spring components on Mule ESB server but I'm worried about opened connections after my server or AD server restarts or communication problems.
How can I:
prevent my code from opened connections after my server restart
reconnect, recreate connections after AD communications problems

Apache commons DBCP doesn't try to reconnect if DB is down at application startup

The Spring application restarts itself due to Bean creation failure what is caused by the connection exception. The Exception is dropped at com.informix.jdbc.IfxDriver.connect(IfxDriver.java:243)
at org.apache.commons.dbcp2.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
This happens if we stop the DB before the application startup.
That case works fine when DB gets down and then trying to reconnect after the application startup.
Is there any way, any settings to set the DBCP to try to reconnect automatically?

Will Oracle database connection pool recover from the database server restart?

If the server running Oracle database reboots, this probably should invalidate all previous JDBC connections in the connection pool (running as part of application on another server).
Some connection pools can handle this, others require manual re-initialization, about Oracle I do not know. Would Oracle connection pool (versions 11g and up) be able to detect such situation and recover, or do I need to check for this myself and reinitialize?
Ideally, I would like to know also that would happen for the connection in use that has been borrowed from the pool. Would such connection proxy be able to use the rebooted server?
I have read http://docs.oracle.com/cd/B10501_01/java.920/a96654/connpoca.htm without particular success.

Unable to locate JDBC data source

I have a query. My application is deployed using WebLogic server, where a JDBC data source is configured. The application config file is configured to pick up the JNDI name and make connectivity to connection pool at application startup. When there is no network connectivity, it fails to resolve the JDBC data source. On resuming network connectivity, we have to restart the server in order to get the JDBC data source working.
Is there any way to dynamically enable JDBC data source in WebLogic or to resolve it after a network failure once connectivity is back instead of restarting the server?
Weblogic does it automatically if you set the "initial connection" to 0 in Datasource connection pool. But you have to rewrite your application to periodically check, if the datasouce is UP or DOWN.

JDBC Connection Link Failure - How to fail over?

I have a stand-alone Java windows application developed based on Swing. It connects to a MySQL database for data storage. In case the database connection fails, I am getting a link failure exception from the MySQL JDBC driver (MySQLNonTransientConnectionException). I don't want to re-instantiate my database connection object or the whole program in case such a link failure issue happens. I just want to tell the user to try again later without having to restart the entire application. If the user is asked to restart the entire application, that would probably give a negative impression on the quality of the program. What do you think would be the preferred way for a standard java application to fail-over after such a database link failure without having to re-instantiate all the communication objects? Thanks in advance.
Use a Connection Pool (such as C3PO or DBCP). Your application takes the Connections from the pool, executes the statement(s) and puts the Connection back into the pool. The pool can be configured to test the JDBC Connections. For example, if they become stale, they can be automatically reinstantiated by the pool.
If your application takes the Connection from the pool, it will be a valid Connection. Let the pool handle the management of valid/invalid/stale JDBC Connections.

Categories