Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sk.kuk.arg;
- import com.alta189.sqlLibrary.MySQL.mysqlCore;
- import com.alta189.sqlLibrary.SQLite.sqlCore;
- import java.net.MalformedURLException;
- import java.sql.ResultSet;
- import java.util.logging.Logger;
- public class SqlHandler {
- public mysqlCore manageMySQL; // MySQL handler
- public sqlCore manageSQLite; // SQLite handler
- public String logPrefix = "[ARG] ";
- public static String mysql_host = "";
- public static String user = "";
- public static String pass = "";
- public static String database = "";
- public static Boolean use_mysql=true;
- public static Logger log = Logger.getLogger("Minecraft");
- ARG plugin;
- SqlHandler(ARG plugin) {
- this.plugin = plugin;
- }
- public void init(){
- //if(use_mysql){
- manageMySQL = new mysqlCore(log, logPrefix, mysql_host, database, user, pass);
- log.info(logPrefix + "MySQL Initializing");
- // Initialize MySQL Handler
- manageMySQL.initialize();
- try {
- if (manageMySQL.checkConnection()) { // Check if the Connection was successful
- log.info(logPrefix + "MySQL connection successful");
- } else {
- log.severe(logPrefix + "MySQL connection failed");
- use_mysql=false;
- }
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- //}
- /*
- if(!use_mysql){
- log.info(this.logPrefix + "SQLite Initializing");
- // Declare SQLite handler
- this.manageSQLite = new sqlCore(log, this.logPrefix, "argdb", plugin.pFolder.getPath());
- // Initialize SQLite handler
- this.manageSQLite.initialize();
- }
- */
- }
- public void commandQuery(String query){
- // if(use_mysql){
- try {
- manageMySQL.insertQuery(query);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- //}else{
- // manageSQLite.insertQuery(query);
- //}
- }
- public ResultSet sqlQuery(String query) {
- ResultSet result = null;
- //if(use_mysql){
- try {
- result = manageMySQL.sqlQuery(query);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- //}else{
- // result = manageSQLite.sqlQuery(query);
- //}
- return result;
- }
- public Boolean checkTable(String table) {
- Boolean result = false;
- //if(use_mysql){
- try {
- result = manageMySQL.checkTable(table);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- //}else{
- // result=manageSQLite.checkTable(table);
- //}
- return result;
- }
- public Boolean checkConnection() {
- Boolean result = false;
- //if(use_mysql){
- try {
- result = manageMySQL.checkConnection();
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- // }else{
- // result = manageSQLite.checkConnection();
- // }
- return result;
- }
- public void closeConnection(){
- manageMySQL.close();
- }
- }
Add Comment
Please, Sign In to add comment