相关文章推荐
谦虚好学的鸵鸟  ·  Weblogic CVE ...·  3 月前    · 
精明的手套  ·  Oops!!! - 简书·  1 年前    · 
酒量大的芹菜  ·  PyQt5 QImage from ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

My Spring Boot works fine when I generate report using Japser report.

The problem I face is that the application throws a hibernate exception :

Unable to acquire JDBC Connection

I get this error after I generate report many times .

1 running delayed actions on {type: MASTER, group: null, band: 0}
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.fill.JRBaseFiller           : Fill 1: ended
2018-09-20 14:27:55.536 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.fill.JRFillDataset          : Fill 1: closing query executer
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block DEVANAGARI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block BENGALI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block TELUGU
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block TAMIL
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block GUJARATI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block KANNADA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block MALAYALAM
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block ORIYA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block GURMUKHI
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block SINHALA
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block TIBETAN
2018-09-20 14:27:55.539 DEBUG 46148 --- [ XNIO-2 task-27] 
n.s.j.engine.export.JRPdfExporter        : glyph renderer block KHMER
2018-09-20 14:28:25.549  WARN 46148 --- [ XNIO-2 task-27] 
o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: null
2018-09-20 14:28:25.550 ERROR 46148 --- [ XNIO-2 task-27] 
o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not 
available, request timed out after 30000ms.
2018-09-20 14:28:25.556 ERROR 46148 --- [ XNIO-2 task-27] 
c.n.xx.aop.logging.LoggingAspect    : Exception in 
com.xx.xx.web.rest.GrueResource.generateRapportGrue() with cause = 
'org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC 
Connection' and exception = 'Could not open JPA EntityManager for 
transaction; nested exception is 
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC 
Connection'
org.springframework.transaction.CannotCreateTransactionException: Could not 
open JPA EntityManager for transaction; nested exception is 
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC 
Connection
                It depends how long your query runs to get the data for the reports. So you should optimize that. At the end you can have as many connections to the database as your database allows.
– Simon Martinelli
                Sep 20, 2018 at 14:01
                You are mixing things. A Datasource reflects just the configuration of the database connection. And the connection is the physical connection to the database. So the pool would hold a max of 10 connections.
– Simon Martinelli
                Sep 20, 2018 at 16:05
                According to Hikari official article the pool size formula is connections = ((core_count * 2) + effective_spindle_count)
– E.Big
                Dec 11, 2020 at 18:59

I did face the same issues every 2nd day when I was working with jasper reports and finally fixed it by proper understanding because when we work with query based reports we are responsible to close the connection of data source our own so that it return to the pool and available for next use. You have to take care of multiple things 1- get connection from dataSource

DataSourceUtils.getConnection(ds);

2-You must have to close data source connection in any case :better to close it in finally block so that in case of exception connection do not remain open .

finally{closeConnection(con,dataSource);}
public void closeConnection(Connection con,DataSource ds) {
 if (con != null) {
DataSourceUtils.releaseConnection(con, ds);

3-Made changes in application.properties file

spring.datasource.hikari.connectionTimeout=30000   
spring.datasource.hikari.idleTimeout=600000          
spring.datasource.hikari.maxLifetime=1800000      
spring.datasource.hikari.maximumPoolSize=30
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.