SHARE
TWEET

Untitled

a guest May 31st, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package server;
  2.  
  3. import java.sql.*;
  4. import java.security.MessageDigest;
  5. import server.model.player.Client;
  6.  
  7. public class SQL {
  8.  
  9.  
  10.     public static Connection con;
  11.     public static Statement stmt;
  12.  
  13.     public static void createConnection() {
  14.         try {
  15.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  16.             con = DriverManager.getConnection("jdbc:mysql://urlhere","database name","database pass");
  17.             stmt = con.createStatement();
  18.         } catch (Exception e) {
  19.             //e.printStackTrace();
  20.         }
  21.     }
  22.     public static ResultSet query(String s) throws SQLException {
  23.         try {
  24.             if (s.toLowerCase().startsWith("select")) {
  25.                 ResultSet rs = stmt.executeQuery(s);
  26.                 return rs;
  27.             } else {
  28.                 stmt.executeUpdate(s);
  29.             }
  30.             return null;
  31.         } catch (Exception e) {
  32.             destroyConnection();
  33.             createConnection();
  34.             //e.printStackTrace();
  35.         }
  36.         return null;
  37.     }
  38.  
  39.     public static void destroyConnection() {
  40.         try {
  41.             stmt.close();
  42.             con.close();
  43.         } catch (Exception e) {
  44.             //e.printStackTrace();
  45.         }
  46.     }
  47.  
  48.     public static boolean saveHighScore(Client clientToSave) {
  49.         try {
  50.             query("DELETE FROM `skills` WHERE playerName = '"+clientToSave.playerName+"';");
  51.             query("DELETE FROM `skillsoverall` WHERE playerName = '"+clientToSave.playerName+"';");
  52.             query("INSERT INTO `skills` (`playerName`,`Attacklvl`,`Attackxp`,`Defencelvl`,`Defencexp`,`Strengthlvl`,`Strengthxp`,`Hitpointslvl`,`Hitpointsxp`,`Rangelvl`,`Rangexp`,`Prayerlvl`,`Prayerxp`,`Magiclvl`,`Magicxp`,`Cookinglvl`,`Cookingxp`,`Woodcuttinglvl`,`Woodcuttingxp`,`Fletchinglvl`,`Fletchingxp`,`Fishinglvl`,`Fishingxp`,`Firemakinglvl`,`Firemakingxp`,`Craftinglvl`,`Craftingxp`,`Smithinglvl`,`Smithingxp`,`Mininglvl`,`Miningxp`,`Herblorelvl`,`Herblorexp`,`Agilitylvl`,`Agilityxp`,`Thievinglvl`,`Thievingxp`,`Slayerlvl`,`Slayerxp`,`Farminglvl`,`Farmingxp`,`Runecraftlvl`,`Runecraftxp`,`PlayerKills`,`PlayerDeaths`,`NPCKills`) VALUES ('"+clientToSave.playerName+"',"+clientToSave.playerLevel[0]+","+clientToSave.playerXP[0]+","+clientToSave.playerLevel[1]+","+clientToSave.playerXP[1]+","+clientToSave.playerLevel[2]+","+clientToSave.playerXP[2]+","+clientToSave.playerLevel[3]+","+clientToSave.playerXP[3]+","+clientToSave.playerLevel[4]+","+clientToSave.playerXP[4]+","+clientToSave.playerLevel[5]+","+clientToSave.playerXP[5]+","+clientToSave.playerLevel[6]+","+clientToSave.playerXP[6]+","+clientToSave.playerLevel[7]+","+clientToSave.playerXP[7]+","+clientToSave.playerLevel[8]+","+clientToSave.playerXP[8]+","+clientToSave.playerLevel[9]+","+clientToSave.playerXP[9]+","+clientToSave.playerLevel[10]+","+clientToSave.playerXP[10]+","+clientToSave.playerLevel[11]+","+clientToSave.playerXP[11]+","+clientToSave.playerLevel[12]+","+clientToSave.playerXP[12]+","+clientToSave.playerLevel[13]+","+clientToSave.playerXP[13]+","+clientToSave.playerLevel[14]+","+clientToSave.playerXP[14]+","+clientToSave.playerLevel[15]+","+clientToSave.playerXP[15]+","+clientToSave.playerLevel[16]+","+clientToSave.playerXP[16]+","+clientToSave.playerLevel[17]+","+clientToSave.playerXP[17]+","+clientToSave.playerLevel[18]+","+clientToSave.playerXP[18]+","+clientToSave.playerLevel[19]+","+clientToSave.playerXP[19]+","+clientToSave.playerLevel[20]+","+clientToSave.playerXP[20]+","+clientToSave.PlayerKills+","+clientToSave.PlayerDeaths+","+clientToSave.NPCKills+");");
  53.             query("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('"+clientToSave.playerName+"',"+(clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[0]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[1]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[2]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[3]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[4]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[5]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[6]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[7]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[8]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[9]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[10]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[11]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[12]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[13]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[14]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[15]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[16]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[17]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[18]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[19]) + clientToSave.getActionAssistant().getLevelForXP(clientToSave.playerXP[20]))+","+((clientToSave.playerXP[0]) + (clientToSave.playerXP[1]) + (clientToSave.playerXP[2]) + (clientToSave.playerXP[3]) + (clientToSave.playerXP[4]) + (clientToSave.playerXP[5]) + (clientToSave.playerXP[6]) + (clientToSave.playerXP[7]) + (clientToSave.playerXP[8]) + (clientToSave.playerXP[9]) + (clientToSave.playerXP[10]) + (clientToSave.playerXP[11]) + (clientToSave.playerXP[12]) + (clientToSave.playerXP[13]) + (clientToSave.playerXP[14]) + (clientToSave.playerXP[15]) + (clientToSave.playerXP[16]) + (clientToSave.playerXP[17]) + (clientToSave.playerXP[18]) + (clientToSave.playerXP[19]) + (clientToSave.playerXP[20]))+");");
  54.         } catch (Exception e) {
  55.             //e.printStackTrace();
  56.             return false;
  57.         }
  58.         return true;
  59.     }
  60.  
  61.     public static boolean clearBannedUsers(String clientToSave) {
  62.         try {
  63.             query("DELETE FROM `skills` WHERE playerName = '"+clientToSave+"';");
  64.             query("DELETE FROM `skillsoverall` WHERE playerName = '"+clientToSave+"';");
  65.         } catch (Exception e) {
  66.             return false;
  67.         }
  68.         return true;
  69.     }
  70.  
  71.     public static boolean offline() {
  72.         try {
  73.             query("DELETE FROM `online` WHERE id = 1;");
  74.  
  75.         } catch (Exception e) {
  76.             e.printStackTrace();
  77.             return false;
  78.         }
  79.         return true;
  80.     }
  81.  
  82.     public static boolean online() {
  83.         try {
  84.             query("INSERT INTO `online` (id, currentlyonline) VALUES('1','"+Server.getPlayerManager().getPlayerCount()+"');");
  85.  
  86.         } catch (Exception e) {
  87.             e.printStackTrace();
  88.             return false;
  89.         }
  90.         return true;
  91.     }
  92.  
  93. }
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