Spring Boot - Application losing DB connection in PRD - java

I read a lot of questions here in stackoverflow about this subject and I ended with the following code in my application-prd.properties:
#PRD IP
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
# Fix for DB Connection
spring.datasource.tomcat.max-active=10
spring.datasource.tomcat.initial-size=5
spring.datasource.tomcat.max-idle=5
spring.datasource.tomcat.min-idle=1
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1 FROM DUAL
spring.datasource.tomcat.time-between-eviction-runs-millis=5000
spring.datasource.tomcat.min-evictable-idle-time-millis=60000
#Error fix for JSON conversion
spring.jackson.parser.allow-unquoted-control-chars=true
But, for some reason, the Tomcat with my Spring application suddenly loses the connection with the database, giving the following error:
Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
I don't know what should I do. Its been weeks that I'm struggling with it. Is there anything else that I can do? Or can I say that is a firewall issue and the infrastructure team should check something?
Thank you

Also check for connection leaks, might be some txns not closing connection properly that's why pool went out of threshold.

Related

Proper setting of application properties for "No operation allowed connection" exception

Application: Java spring boot + mysql
Story:
application log showed "Could not open JDBC Connecton for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure"
Recovery of the DB instance has been triggered since hardware problem occurred in RDS instance
After 10 mins, the recovery is done.
application log showed "Could not commit JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed." instead of previous exception.
After 45 mins, application resumed normal without manual operations.
Questions:
Will restarting the application solve the problem instantly?
Manual operation might not be the best to resolve such problem. But if I want it be auto resumed shortly, anything I can do to the setting datasource properties? i.e. set spring.datasource.justswap.time-between-eviction-runs-millis shorter?
Current datasource setting:
spring.datasource.xxx.maxActive=700
spring.datasource.xxx.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.xxx.test-on-borrow=false
spring.datasource.xxx.test-while-idle=true
spring.datasource.xxx.time-between-eviction-runs-millis=3600000
spring.datasource.druid.stat-view-servlet.enabled=false

Connection issue while connecting to HANA DB via JDBC

I am connecting HANA DB via ngdbc.jar. Connection is made properly but after running query 3-4 times connection to HANA DB is lost. When I restart my JAVA server again it works for 3-4 times. Can anyone help?
Error Msg-
WARN [org.hibernate.util.JDBCExceptionReporter] (http--0.0.0.0-8080-6) SQL Error: -708, SQLState: 08006
ERROR [org.hibernate.util.JDBCExceptionReporter] (http--0.0.0.0-8080-6) Data receive failed [Connection reset].
INFO [com.ultimatix.controller.MetricsController] (http--0.0.0.0-8080-6) context setMonthFreezeDateorg.hibernate.exception.JDBCConnectionException: could not execute query
ERROR [org.hibernate.transaction.JDBCTransaction] (http--0.0.0.0-8080-6) JDBC rollback failed: com.sap.db.jdbc.exceptions.jdbc40.SQLNonTransientConnectionException: Connection to database server lost; check server and network status [System error: Socket closed]
I can see you are using Hibernate based on your log.
Can you elaborate a little bit on your stack?
As #RC said, you should consider connection pooling instead of opening direct connections if this is what you are doing in your "JAVA" server.
May be your are keeping the connection open for too long and it times out.
These are all guesses, until you can share any logs or sample code.
One more thing, related to the ngjdbc driver only, there is a "reconnect" connection property which by default is set to false.
Regards

Oracle socket read time out error in Spring boot application

I have created a spring boot application. When I put load on the application after sometime load on database server started increasing and I got started socket read time out error.
2016-10-24 21:56:10 [pool-3-thread-296] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - IO Error: Socket read timed out
2016-10-24 21:56:10 [pool-3-thread-296] ERROR
Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
Here is the properties file details of Springboot application
spring.datasource.url=jdbc:oracle:thin:#<ip>:1521:<dbname>
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.initial-size=100
spring.datasource.maxActive=1500
spring.datasource.validationQuery=select 1 from dual
spring.jpa.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
spring.jpa.show-sql = true
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.datasource.pool-prepared-statements=true
spring.datasource.pool-prepared-statements-cache-size=500
spring.datasource.max-open-prepared-statements=500
Since the error is very generic , I am not able to figure out why I am getting socket read timeout exception.
I also need to know what does "[pool-3-thread-296]" mean in exception log ?
Have you tried this? This worked for me
https://springframework.guru/configuring-spring-boot-for-oracle/

Exception when connecting to Sybase using JDBC Driver

I'm new to Sybase database and trying to connect to Sybase using Java JDBC connection and sajdbc4.jar, but getting an error:
java.sql.SQLException: [Sybase][JDBC Driver][SQL Anywhere]Database server not found
Here is my connection string:
jdbc:sqlanywhere:uid=user;pwd=xxxx;eng=xx_sql;database=dummy;links=tcpip(host=xx.xx.xx.xx)
Firstly ensure that you point the database file to the SQL Anywhere Server and restart the server.
Secondly analyze your database logs, check if you can trace the connectivity with SQL PLUS or any other database connectivity tools.
If you are able to solve it, then that's fine or else I suspect that the issue to be related to this issue on SO here
As per this question, please make the following changes and I guess that the issue should be resolved
jdbc:sqlanywhere:Server=yourservername;uid=user;pwd=xxxx;port=2638;eng=xx_sql;database=dummy;links=tcpip(port=2638)
It is mandatory to mention the use of TCP/IP protocol to yourJDBC driver through the connection string above!
Hope this helps!

SQL Nested Exception

I am facing this problem.
Stackstrace
2014-09-22 16:50:35,292 [main] WARN org.hibernate.cfg.SettingsFactory
- Could not obtain connection metadata org.apache.commons.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (IO Error: Connection reset) at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
can any one please let me know the cause of this , oracle version is 11g
Your stack trace specifies that you are unable to connect to your database.
Make sure that your database server is listening on the correct port (1521 default).
Check your firewall or any setting that prevents you from accessing your database server
Check your dataSource settings for any errors.
If your database is an external one, make sure that the listener.ora is configured correctly.

Categories