我正在使用Java来播放框架版本2.3.7,当我试图调用存储过程时抛出以下异常:
[错误]应用程序-尝试通过礼品加载图片时出错。
等待可用的免费连接时超时。
java.sql.sqlexception:等待可用连接时超时。
在com.jolbox.bonecp.defaultconnectionstrategy.getconnectioninternal(defaultconnectionstrategy.java:88)~[bonecp-0.8.0.release.jar:na]
在com.jolbox.bonecp.abstractconnectionstrategy.getconnection(abstractconnectionstrategy.java:90)~[bonecp-0.8.0.release.jar:na]
在com.jolbox.bonecp.bonecp.getconnection(bonecp.java:553)~[bonecp-0.8.0.release.jar:na]
在com.jolbox.bonecp.bonecpdatasource.getconnection(bonecpdatasource.java:131)~[bonecp-0.8.0.release.jar:na]
-在play.api.db.dbapi$class.getconnection(db.scala:66)~[play-jdbc_2.11-2.3.7.jar:2.3.7]
Java代码:

CallableStatement cst = null;
ResultSet rs = null;
Connection conn = DB.getConnection();
List<Picture> pictures = null;
try {
    conn = DB.getConnection();
    for (Gift gift : giftList) {
        cst = conn.prepareCall("{CALL sp_set_pictures_LOAD_PICTURES_BY_GIFT(?)}");
        cst.setInt(1, gift.getId());
        rs = cst.executeQuery();
        if (rs.next()) {
            pictures = new ArrayList<Picture>();
            do {
                Picture p = new Picture(rs.getInt(1));
                pictures.add(p);
            } while (rs.next());
            gift.setPictures(pictures);
        }
    }
} catch (Exception e) {
    Logger.error("An error has been occurred tryning loading the Pictures by Gift.\n" + e.getMessage(), e);
} finally {
    if (cst != null)
        cst = null;
    close(conn);
}

application.conf文件:
db.default.autocommit=true
db.default.isolation=READ_COMMITTED
db.default.partitionCount=2
db.default.maxConnectionsPerPartition=5
db.default.minConnectionsPerPartition=5
db.default.acquireIncrement=1
db.default.acquireRetryAttempts=10
db.default.acquireRetryDelay=5 seconds
db.default.connectionTimeout=20 second
db.default.idleMaxAge=10 minute
db.default.idleConnectionTestPeriod=5 minutes
db.default.initSQL="SELECT 1"
db.default.logStatements=false
db.default.maxConnectionAge=1 hour
db.default.queryExecuteTimeLimit=1 second

最佳答案

你打了两次电话。也许正因为如此,JDBC驱动程序创建了两个连接,但您只关闭了第二个连接。

关于java - 数据库超时,等待可用的免费连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29081125/

10-10 07:34