Guest User

Untitled

a guest
Feb 17th, 2020
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static MySQL getMySQL() {
  2. return mysql;
  3. }
  4.  
  5. public void connectMySQL() {
  6. if (getDrive().equalsIgnoreCase("MySql")) {
  7. String Host = getConfig().getString("Options.Host");
  8. String Port = getConfig().getString("Options.Port");
  9. String Database = getConfig().getString("Options.Database");
  10. String User = getConfig().getString("Options.User");
  11. String Pass = getConfig().getString("Options.Password");
  12. creator();
  13. mysql = new MySQL(Host, Port, Database, User, Pass);
  14. PreparedStatement statement = mysql.prepareStatement("CREATE TABLE IF NOT EXISTS BeastTokens(UUID varchar(36), name VARCHAR(16), tokens double)");
  15. mysql.update(statement);
  16. statement = mysql.prepareStatement("ALTER TABLE BeastTokens MODIFY COLUMN tokens DOUBLE NOT NULL");
  17. mysql.update(statement);
  18.  
  19. statement = mysql.prepareStatement("SHOW COLUMNS FROM `BeastTokens` LIKE 'lastdate'");
  20. ResultSet result = BeastTokens.getMySQL().query(statement);
  21.  
  22. try {
  23. if (!result.next()) {
  24. DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
  25. Date date = new Date();
  26.  
  27. statement = mysql.prepareStatement("ALTER TABLE BeastTokens ADD COLUMN lastdate VARCHAR(16) DEFAULT '"+dateFormat.format(date)+"' AFTER tokens");
  28. mysql.update(statement);
  29. }
  30.  
  31. } catch (Exception e) {
  32. // TODO: handle exception
  33. }
  34. }
  35. }
  36.  
  37. public void creator(){
  38. String jdbcDriver = "com.mysql.jdbc.Driver";
  39. String Host = getConfig().getString("Options.Host");
  40. String Port = getConfig().getString("Options.Port");
  41. String Database = getConfig().getString("Options.Database");
  42. String User = getConfig().getString("Options.User");
  43. String Pass = getConfig().getString("Options.Password");
  44.  
  45. String myTableName = "CREATE TABLE IF NOT EXISTS BeastTokens(UUID varchar(36), name VARCHAR(16), tokens double)";
  46. try {
  47. Class.forName(jdbcDriver);
  48. con = (Connection) DriverManager.getConnection("jdbc:mysql://" + Host + ":"+Port+"/" + Database, User, Pass);
  49. statement = (Statement) con.createStatement();
  50. statement.executeUpdate(myTableName);
  51. System.out.println("BeastTokens Table Created");
  52. }
  53. catch (SQLException e ) {
  54. System.out.println("An error has occured on BeastTokens Table Creation");
  55. e.printStackTrace();
  56. }
  57. catch (ClassNotFoundException e) {
  58. System.out.println("BeastTokens An Mysql drivers were not found");
  59. }
  60.  
  61. }
RAW Paste Data