現在、メインデータベースに接続するオープンプールが1つあり、完全に機能します。しかし今、私は別のデータベースのために新しいプールを開きたいと思います。新しいプールを最初のプールとまったく同じように設定しました。明らかにデータベース名などを編集しました。setupHikari()メソッドをロードしてもエラーは表示されませんが、実際のステートメントを実行しようとすると、多くのエラーが発生します。
Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization at com.zaxxer.hikari.pool.HikariPool.initializeConnections(HikariPool.Java:580) ~[?:?] at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.Java:150) ~[?:?] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.Java:96) ~[?:?] at com.thecodexmc.GameLibrary.xenforo.XenUtils.getUserGroupID(XenUtils.Java:51) ~[?:?] at com.thecodexmc.GameLibrary.game.GameListeners.onLogin(GameListeners.Java:334) ~[?:?] at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79] at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57) ~[?:1.7.0_79] at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[?:1.7.0_79] at Java.lang.reflect.Method.invoke(Method.Java:606) ~[?:1.7.0_79] at org.bukkit.plugin.Java.JavaPluginLoader$1.execute(JavaPluginLoader.Java:306) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] ... 13 more Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections at Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_79] at Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:57) ~[?:1.7.0_79] at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45) ~[?:1.7.0_79] at Java.lang.reflect.Constructor.newInstance(Constructor.Java:526) ~[?:1.7.0_79] at com.mysql.jdbc.Util.handleNewInstance(Util.Java:407) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.Util.getInstance(Util.Java:382) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.SQLError.createSQLException(SQLError.Java:1013) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3593) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:3525) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.Java:931) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.Java:4031) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.Java:1296) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.Java:2338) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.Java:2371) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.Java:2163) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.Java:794) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.Java:47) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at Sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_79] at Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.Java:57) ~[?:1.7.0_79] at Sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.Java:45) ~[?:1.7.0_79] at Java.lang.reflect.Constructor.newInstance(Constructor.Java:526) ~[?:1.7.0_79] at com.mysql.jdbc.Util.handleNewInstance(Util.Java:407) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.Java:378) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.Java:305) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.Java:440) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.Java:138) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.Java:108) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.Java:495) ~[?:?] at com.zaxxer.hikari.pool.HikariPool.initializeConnections(HikariPool.Java:564) ~[?:?] at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.Java:150) ~[?:?] at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.Java:96) ~[?:?] at com.thecodexmc.GameLibrary.xenforo.XenUtils.getUserGroupID(XenUtils.Java:51) ~[?:?] at com.thecodexmc.GameLibrary.game.GameListeners.onLogin(GameListeners.Java:334) ~[?:?] at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79] at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57) ~[?:1.7.0_79] at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43) ~[?:1.7.0_79] at Java.lang.reflect.Method.invoke(Method.Java:606) ~[?:1.7.0_79] at org.bukkit.plugin.Java.JavaPluginLoader$1.execute(JavaPluginLoader.Java:306) ~[server.jar:git-PaperSpigot-7aa4900-62a2169] ... 13 more
私はここで何が間違っているのですか?これが私のXenSQLクラスで、これが問題の原因です。
public class XenSQL {
private static XenSQL instance;
private HikariDataSource hikari;
public XenSQL() {
instance = this;
}
public void setupHikari() {
hikari = new HikariDataSource();
hikari.setMaximumPoolSize(10);
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
hikari.addDataSourceProperty("serverName", Host);
hikari.addDataSourceProperty("port", port);
hikari.addDataSourceProperty("databaseName", database);
hikari.addDataSourceProperty("user", user);
hikari.addDataSourceProperty("password", password);
System.out.println("[XenSQL] HikariCP connected to the database successfully.");
}
public void queryUpdate(String query) {
Connection connection = null;
try {
connection = hikari.getConnection();
PreparedStatement pre = connection.prepareStatement(query);
pre.executeUpdate();
pre.close();
} catch (SQLException e) {
System.out.println("[XenSQL] Error whilst executing the query \"" + query + "\": " + e.getMessage());
} finally {
closeConnection(connection);
}
}
public void closeConnection(Connection connection) {
if(connection != null) {
try {
connection.close();
} catch(SQLException e) {
e.printStackTrace();
}
}
}
public HikariDataSource getHikari() {
return hikari;
}
public static XenSQL getInstance() {
return instance;
}
}
明らかな理由でSQL情報を削除しましたが、ここで何が問題なのかわかりません。
MySQLNonTransientConnectionExceptionの場合:接続が多すぎます
あなたが持っているいくつかのオプションは次のとおりです。
HTH
Pom.xmlでmysqlの依存関係に移動し、バージョンタグを削除します。
<version>X.X.XX</version>
プロジェクトを再起動します