Repository for lakemenbane
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

/*
* Copyright 2013 MagicBane Emulator Project
* All Rights Reserved
*/
package engine.pooling;
import engine.gameManager.ConfigManager;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionPool extends LinkedObjectPool<Connection> {
static {
//Register the Driver
try {
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ConnectionPool() {
super(10);
}
@Override
protected Connection makeNewObject() {
// Protocol
String sqlURI = "jdbc:mysql://";
sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue();
sqlURI += '/' + ConfigManager.MB_DATABASE_NAME.getValue() + '?';
sqlURI += "useServerPrepStmts=true";
sqlURI += "&cachePrepStmts=false";
sqlURI += "&cacheCallableStmts=true";
sqlURI += "&characterEncoding=utf8";
Connection out = null;
try {
out = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
ConfigManager.MB_DATABASE_PASS.getValue());
} catch (SQLException e) {
e.printStackTrace();
}
return out;
}
@Override
protected void resetObject(Connection obj) {
}
}