Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.neyox.sql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin {
- private Connection conn;
- public String host, database, username, password;
- public int port;
- @Override
- public void onEnable() {
- host = "localhost";
- port = 3306;
- database = "tutorial";
- username = "root";
- password = "password";
- try {
- synchronized (this) {
- if (getConn() != null && !getConn().isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- setConn(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
- }
- } catch(SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public Connection getConn() {
- return conn;
- }
- public void setConn(Connection connection) {
- this.conn = connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement