Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import net.md_5.bungee.api.ChatColor;
- public class MySQL {
- private Connection conn;
- public void connect(String host, int port, String database, String user, String password){
- if(!isConnected()){
- try {
- conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, user, password);
- System.out.println("[HardSword] - [MySQL] Connection etablie avec le serveur !");
- System.out.println("-----------------------------");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public void disconnect(){
- if(isConnected()){
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected(){
- try {
- if((conn == null) || (conn.isClosed()) || conn.isValid(5)){
- return false;
- }
- return true;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public Connection getConnection(){
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement