连接不可用,请求在30002ms后超时

7nbnzgx9  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(625)

在成功运行应用程序后,我面临一个连接错误。我的代码如下。我是在使用高效的连接处理,还是需要改进它?在运行应用程序时,在哪里可以看到我的活动、已用和空闲连接状态?

@Service
public class printChallan extends JdbcDaoSupport{

@Autowired
DataSource dataSource;

@PostConstruct
private void initialize() {setDataSource(dataSource);}

public boolean printAdmissionForm(HttpServletRequest request)
{
    java.sql.Connection conn = null;
    try {
            conn = getJdbcTemplate().getDataSource().getConnection();
            //conn = dataSource.getConnection();
            jasperdesign = JRXmlLoader.load(totalPath);
            JasperReport jasperReport = JasperCompileManager.compileReport(jasperdesign);
            jasperPrint = JasperFillManager.fillReport(jasperReport, param, conn);
        } catch (Exception e) 
        {
           if(conn != null) conn.close(); // Does I need to close Connection Manually
            e.printStackTrace();
        }
return true;
}
public boolean callProcedure(HttpServletRequest request){
CallableStatement cs = null;
try 
{
   cs = getJdbcTemplate().getDataSource().getConnection()   // does this connection need to be closed.
   .prepareCall("{? = call FUNC_CHALLAN_PRINT_TYPE(?)}");
    cs.registerOutParameter(1, Types.VARCHAR);
    cs.setString(2, challanNbr);
    cs.execute();
    Status = cs.getString(1);
    cs.close();
    return Status;
} catch (SQLException e) {
            logger.debug("Error occured while getting Challan record" + e.getMessage());
}finally
{

}
return true;
}
}

应用程序属性

spring.datasource.url=jdbc:oracle:thin:@172.19.10.37:1521:ORCL
spring.datasource.username=app
spring.datasource.password=app
spring.datasource.platform=ORACLE
q9rjltbz

q9rjltbz1#

如果不关闭连接,则池将满,并且在尝试获取新连接时将超时。
如果您没有关闭连接,只需更改为使用资源进行尝试,它就会自动关闭

try (java.sql.Connection conn = getJdbcTemplate().getDataSource().getConnection()) {

相同的解决方案 CallableStatement

相关问题