Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.nestway.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQL
- extends Database
- {
- private final String user;
- private final String database;
- private final String password;
- private final String port;
- private final String hostname;
- public MySQL(String hostname, String port, String database, String username, String password)
- {
- this.hostname = hostname;
- this.port = port;
- this.database = database;
- this.user = username;
- this.password = password;
- }
- public Connection openConnection()
- throws SQLException, ClassNotFoundException
- {
- if (checkConnection()) {
- return this.connection;
- }
- Class.forName("com.mysql.jdbc.Driver");
- this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?autoReconnect=true", this.user, this.password);
- return this.connection;
- }
- }
Add Comment
Please, Sign In to add comment