Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package me.mike_lolz.shadoweco.utils.mysql;
  2.  
  3. import me.mike_lolz.shadoweco.Core;
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. public class MySQL {
  11.  
  12. private static Connection connection;
  13. private static String username;
  14. private static String host;
  15. private static String password;
  16. private static String database;
  17. private static int port;
  18. public static Statement statement;
  19.  
  20.  
  21. public MySQL(){
  22.  
  23. this.username = Core.getInstance().getConfig().getString("MySQL.username");
  24. this.host = Core.getInstance().getConfig().getString("MySQL.host");
  25. this.password = Core.getInstance().getConfig().getString("MySQL.password");
  26. this.database = Core.getInstance().getConfig().getString("MySQL.database");
  27. this.port = Core.getInstance().getConfig().getInt("MySQL.port");
  28. }
  29.  
  30.  
  31. public static void connect() throws SQLException,ClassNotFoundException{
  32.  
  33. Class.forName("com.mysql.jdbc.Driver");
  34. connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + username + "&password=" + password + "&autoReconnect=true");
  35.  
  36. statement = connection.createStatement();
  37.  
  38. if(connection != null && !connection.isClosed()){
  39. return;
  40. }
  41. synchronized (Core.getInstance()){
  42. if(connection !=null && !connection.isClosed()){
  43. return;
  44. }
  45. }
  46. }
  47. public static void createTable(){
  48.  
  49. String balances = "CREATE TABLE IF NOT EXISTS Balances(" +
  50. "PlayerName VARCHAR(50)" +
  51. "PlayerUUID LONGTEXT" +
  52. "Balance DOUBLE";
  53.  
  54. try {
  55. statement.executeUpdate(balances);
  56. } catch (SQLException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60.  
  61. public static Connection getConnection(){
  62. return connection;
  63. }
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement