Guest User

Untitled

a guest
Dec 8th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. package sk.kuk.arg;
  2.  
  3. import com.alta189.sqlLibrary.MySQL.mysqlCore;
  4. import com.alta189.sqlLibrary.SQLite.sqlCore;
  5. import java.net.MalformedURLException;
  6. import java.sql.ResultSet;
  7. import java.util.logging.Logger;
  8.  
  9.  
  10. public class SqlHandler {
  11.  
  12. public mysqlCore manageMySQL; // MySQL handler
  13. public sqlCore manageSQLite; // SQLite handler
  14. public String logPrefix = "[ARG] ";
  15. public static String mysql_host = "";
  16. public static String user = "";
  17. public static String pass = "";
  18. public static String database = "";
  19. public static Boolean use_mysql=true;
  20. public static Logger log = Logger.getLogger("Minecraft");
  21. ARG plugin;
  22.  
  23. SqlHandler(ARG plugin) {
  24. this.plugin = plugin;
  25. }
  26.  
  27. public void init(){
  28. //if(use_mysql){
  29. manageMySQL = new mysqlCore(log, logPrefix, mysql_host, database, user, pass);
  30.  
  31. log.info(logPrefix + "MySQL Initializing");
  32. // Initialize MySQL Handler
  33. manageMySQL.initialize();
  34.  
  35. try {
  36. if (manageMySQL.checkConnection()) { // Check if the Connection was successful
  37. log.info(logPrefix + "MySQL connection successful");
  38. } else {
  39. log.severe(logPrefix + "MySQL connection failed");
  40. use_mysql=false;
  41. }
  42. } catch (MalformedURLException e) {
  43. e.printStackTrace();
  44. } catch (InstantiationException e) {
  45. e.printStackTrace();
  46. } catch (IllegalAccessException e) {
  47. e.printStackTrace();
  48. }
  49. //}
  50. /*
  51. if(!use_mysql){
  52. log.info(this.logPrefix + "SQLite Initializing");
  53.  
  54. // Declare SQLite handler
  55. this.manageSQLite = new sqlCore(log, this.logPrefix, "argdb", plugin.pFolder.getPath());
  56.  
  57. // Initialize SQLite handler
  58. this.manageSQLite.initialize();
  59. }
  60. */
  61.  
  62. }
  63.  
  64. public void commandQuery(String query){
  65. // if(use_mysql){
  66. try {
  67. manageMySQL.insertQuery(query);
  68. } catch (MalformedURLException e) {
  69. e.printStackTrace();
  70. } catch (InstantiationException e) {
  71. e.printStackTrace();
  72. } catch (IllegalAccessException e) {
  73. e.printStackTrace();
  74. }
  75. //}else{
  76. // manageSQLite.insertQuery(query);
  77. //}
  78. }
  79.  
  80. public ResultSet sqlQuery(String query) {
  81. ResultSet result = null;
  82. //if(use_mysql){
  83. try {
  84. result = manageMySQL.sqlQuery(query);
  85. } catch (MalformedURLException e) {
  86. e.printStackTrace();
  87. } catch (InstantiationException e) {
  88. e.printStackTrace();
  89. } catch (IllegalAccessException e) {
  90. e.printStackTrace();
  91. }
  92. //}else{
  93. // result = manageSQLite.sqlQuery(query);
  94. //}
  95. return result;
  96. }
  97.  
  98. public Boolean checkTable(String table) {
  99. Boolean result = false;
  100. //if(use_mysql){
  101. try {
  102. result = manageMySQL.checkTable(table);
  103. } catch (MalformedURLException e) {
  104. e.printStackTrace();
  105. } catch (InstantiationException e) {
  106. e.printStackTrace();
  107. } catch (IllegalAccessException e) {
  108. e.printStackTrace();
  109. }
  110. //}else{
  111. // result=manageSQLite.checkTable(table);
  112. //}
  113. return result;
  114. }
  115.  
  116. public Boolean checkConnection() {
  117. Boolean result = false;
  118. //if(use_mysql){
  119. try {
  120. result = manageMySQL.checkConnection();
  121. } catch (MalformedURLException e) {
  122. e.printStackTrace();
  123. } catch (InstantiationException e) {
  124. e.printStackTrace();
  125. } catch (IllegalAccessException e) {
  126. e.printStackTrace();
  127. }
  128. // }else{
  129. // result = manageSQLite.checkConnection();
  130. // }
  131. return result;
  132. }
  133.  
  134. public void closeConnection(){
  135. manageMySQL.close();
  136. }
  137.  
  138. }
Add Comment
Please, Sign In to add comment