Refactored mysql connector
This commit is contained in:
1 parent
fd32bbee91
commit
a5f6851162
1 file changed
+7
-11
@@ -1,8 +1,7 @@
|
|||||||
package netneutrality.db;
|
package netneutrality.db;
|
||||||
|
|
||||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class MysqlConnector {
|
public class MysqlConnector {
|
||||||
@@ -26,15 +25,12 @@ public class MysqlConnector {
|
|||||||
* @return {@link MysqlConnector}
|
* @return {@link MysqlConnector}
|
||||||
*/
|
*/
|
||||||
public MysqlConnector connect() throws SQLException {
|
public MysqlConnector connect() throws SQLException {
|
||||||
MysqlDataSource dataSource = new MysqlDataSource();
|
try {
|
||||||
dataSource.setUser(dbUser);
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
dataSource.setPassword(dbPass);
|
c = DriverManager.getConnection("jdbc:mysql://" + dbHost + ":3306/" + dbName, dbUser, dbPass);
|
||||||
dataSource.setServerName(dbHost);
|
} catch (ClassNotFoundException e) {
|
||||||
dataSource.setPort(3306);
|
e.printStackTrace();
|
||||||
dataSource.setDatabaseName(dbName);
|
}
|
||||||
dataSource.setAutoReconnect(true);
|
|
||||||
dataSource.setConnectTimeout(5000);
|
|
||||||
c = dataSource.getConnection();
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user