SHARE
TWEET

Untitled

a guest Sep 21st, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package bungeeonlinetime;
  2.  
  3. import java.io.PrintStream;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. public class MySQL
  11. {
  12.   private Connection connection;
  13.   private String prefix;
  14.   private String host;
  15.   private Integer port;
  16.   private String database;
  17.   private String username;
  18.   private String password;
  19.  
  20.   public MySQL(String host, Integer port, String database, String username, String password, String pluginname)
  21.   {
  22.     this.host = host;
  23.     this.port = port;
  24.     this.database = database;
  25.     this.username = username;
  26.     this.password = password;
  27.     this.prefix = ("[" + pluginname + "] MySQL: ");
  28.     createConnection();
  29.   }
  30.  
  31.   public void createConnection()
  32.   {
  33.     try
  34.     {
  35.       Class.forName("com.mysql.jdbc.Driver");
  36.       this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database + "?user=" + this.username + "&password=" + this.password + "&autoReconnect=true");
  37.       System.out.println(this.prefix + "Connected.");
  38.     }
  39.     catch (SQLException|ClassNotFoundException e)
  40.     {
  41.       System.out.println(this.prefix + e.getMessage());
  42.     }
  43.   }
  44.  
  45.   public String getPrefix()
  46.   {
  47.     return this.prefix;
  48.   }
  49.  
  50.   public Connection getConnection()
  51.   {
  52.     return this.connection;
  53.   }
  54.  
  55.   public Boolean isConnected()
  56.   {
  57.     if (this.connection != null) {
  58.       return Boolean.valueOf(true);
  59.     }
  60.     return Boolean.valueOf(false);
  61.   }
  62.  
  63.   public void create(String string)
  64.   {
  65.     try
  66.     {
  67.       Statement statement = this.connection.createStatement();
  68.       statement.executeUpdate(string);
  69.       statement.close();
  70.     }
  71.     catch (SQLException e)
  72.     {
  73.       System.out.println(this.prefix + e.getMessage());
  74.     }
  75.   }
  76.  
  77.   public ResultSet get(String string)
  78.   {
  79.     ResultSet resultset = null;
  80.     try
  81.     {
  82.       resultset = this.connection.createStatement().executeQuery(string);
  83.     }
  84.     catch (SQLException e)
  85.     {
  86.       System.out.println(this.prefix + e.getMessage());
  87.     }
  88.     return resultset;
  89.   }
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top