我知道这将是重复的问题,但我觉得我的问题有点不同。太多的连接弹簧引导jdbc
我JdbcDAO类,如
@Component
public class JdbcUserDAO implements UserDAO {
@Autowired
MyJdbc myJdbc;
}
我已经如下定义MyJdbc类:
@Component
public class MyJdbc {
@Autowired
protected JdbcTemplate jdbc;
}
在MyJdbc类我定义的插件和BATCHUPDATE,并呼吁他们通过JDBC变量。 它会创建太多的连接异常吗?
我在application.properties文件中定义的JDBC参数:
spring.datasource.url=#databaseurl
spring.datasource.username=#username
spring.datasource.password=#password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.test-on-borrow=true
spring.datasource.max-active=100
spring.datasource.max-wait=10000
spring.datasource.min-idle=10
spring.datasource.validation-query=SELECT 1
spring.datasource.time-between-eviction-runs-millis= 5000
spring.datasource.min-evictable-idle-time-millis=30000
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=true
spring.datasource.test-on-return=false
我得到异常:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
我已经做了很多更改application.properties文件的各种常数但它不起作用。我的数据库托管在AWS RDS上。
但对于更新团块图像值我做的:
blob= myJdbc.jdbc.getDataSource().getConnection().createBlob();
blob.setBytes(1, str.getBytes());
pstmt = myJdbc.jdbc.getDataSource().getConnection().prepareStatement("update user_profile set profileImage=? where user_profile.id in (select id from user_login where email=?)");
错误来自MySQL,而不是您的应用程序,您知道您的RDS实例能够应对多少个连接吗?我的猜测是它小于100. –
你有没有理由使用普通的Jdbc API而不是Spring Data或JPA? –
@DaveBower:我确实显示了像'max_connections'这样的全局变量;它显示66 – Chetan