Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cadiducho.tutorialbukkit;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * Objeto para conexiones de MySQL
- * @author Huskehhh base original, Cadiducho actualización
- */
- public class MySQL {
- protected Connection connection;
- private final String user, database, password, port, 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 boolean checkConnection() throws SQLException {
- return connection != null && !connection.isClosed();
- }
- public Connection getConnection() {
- return connection;
- }
- public boolean closeConnection() throws SQLException {
- if (connection == null) {
- return false;
- }
- connection.close();
- return true;
- }
- public Connection openConnection() throws SQLException, ClassNotFoundException {
- if (checkConnection()) {
- return connection;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://"
- + this.hostname + ":" + this.port + "/" + this.database, this.user, this.password);
- return connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement