我知道這將是重複的問題,但我覺得我的問題有點不同。太多的連接彈簧引導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