SHARE
TWEET

Untitled

a guest Jun 4th, 2017 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.rs2hd.io;
  2.  
  3. import java.sql;
  4. import java.security.MessageDigest;
  5. import java.util;
  6. import java.lang;
  7. import com.rs2hd.Server;
  8. import com.rs2hd.GameEngine;
  9. import com.rs2hd.model.Player;
  10. import com.rs2hd.util.Misc;
  11.  
  12. public class SQL {
  13.  
  14.  
  15.     public static Connection con = null;
  16.     public static Statement stmt;
  17.  
  18.     public static void createConnection() {
  19.         try {
  20.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  21.         String IP="localhost";
  22.             String DB="highscores";
  23.             String User="root";
  24.             String Pass="26vapor26";
  25.             con = DriverManager.getConnection("jdbc:mysql://"+IP+"/"+DB, User, Pass);
  26.             stmt = con.createStatement();
  27.             Misc.println("Connection to SQL database successful!");
  28.         } catch (Exception e) {
  29.         Misc.println("Connection to SQL database failed");
  30.             e.printStackTrace();
  31.         }
  32.     }
  33.     public static ResultSet query(String s) throws SQLException {
  34.         try {
  35.             if (s.toLowerCase().startsWith("select")) {
  36.                 ResultSet rs = stmt.executeQuery(s);
  37.                 Misc.println("Success");
  38.                 return rs;
  39.             } else {
  40.                 stmt.executeUpdate(s);
  41.             }
  42.             return null;
  43.         } catch (Exception e) {
  44.             destroyConnection();
  45.             createConnection();
  46.             Misc.println("Failed");
  47.             e.printStackTrace();
  48.         }
  49.         return null;
  50.     }
  51.  
  52.     public static void destroyConnection() {
  53.         try {
  54.             stmt.close();
  55.             con.close();
  56.             Misc.println("Destruction from SQL database successful");
  57.         } catch (Exception e) {
  58.         Misc.println("Destruction from SQL database successful");
  59.             e.printStackTrace();
  60.         }
  61.     }
  62.  
  63.     public static boolean saveHighScore(Player p) {
  64.         try {
  65.             query("DELETE FROM `skills` WHERE playerName = '"+p.username+"';");
  66.             query("DELETE FROM `skillsoverall` WHERE playerName = '"+p.username+"';");
  67.             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`,`Hunterlvl`,`Hunterxp`,`Constructionlvl`,`Constructionxp`,`Summoninglvl`,`Summoningxp`) VALUES ('"+p.username+"',"+p.skillLvl[0]+","+p.skillXP[0]+","+p.skillLvl[1]+","+p.skillXP[1]+","+p.skillLvl[2]+","+p.skillXP[2]+","+p.skillLvl[3]+","+p.skillXP[3]+","+p.skillLvl[4]+","+p.skillXP[4]+","+p.skillLvl[5]+","+p.skillXP[5]+","+p.skillLvl[6]+","+p.skillXP[6]+","+p.skillLvl[7]+","+p.skillXP[7]+","+p.skillLvl[8]+","+p.skillXP[8]+","+p.skillLvl[9]+","+p.skillXP[9]+","+p.skillLvl[10]+","+p.skillXP[10]+","+p.skillLvl[11]+","+p.skillXP[11]+","+p.skillLvl[12]+","+p.skillXP[12]+","+p.skillLvl[13]+","+p.skillXP[13]+","+p.skillLvl[14]+","+p.skillXP[14]+","+p.skillLvl[15]+","+p.skillXP[15]+","+p.skillLvl[16]+","+p.skillXP[16]+","+p.skillLvl[17]+","+p.skillXP[17]+","+p.skillLvl[18]+","+p.skillXP[18]+","+p.skillLvl[19]+","+p.skillXP[19]+","+p.skillLvl[20]+","+p.skillXP[20]+","+p.skillLvl[21]+","+p.skillXP[21]+","+p.skillLvl[22]+","+p.skillXP[22]+","+p.skillLvl[23]+","+p.skillXP[23]+");");
  68.             query("INSERT INTO `skillsoverall` (`playerName`,`lvl`,`xp`) VALUES ('"+p.username+"',"+(p.skillLvl[0] + p.skillLvl[1] + p.skillLvl[2] + p.skillLvl[3] + p.skillLvl[4] + p.skillLvl[5] + p.skillLvl[6] + p.skillLvl[7] + p.skillLvl[8] + p.skillLvl[9] + p.skillLvl[10] + p.skillLvl[11] + p.skillLvl[12] + p.skillLvl[13] + p.skillLvl[14] + p.skillLvl[15] + p.skillLvl[16] + p.skillLvl[17] + p.skillLvl[18] + p.skillLvl[19] + p.skillLvl[20] + p.skillLvl[21] + p.skillLvl[22] + p.skillLvl[23])+","+((p.skillXP[0]) + (p.skillXP[1]) + (p.skillXP[2]) + (p.skillXP[3]) + (p.skillXP[4]) + (p.skillXP[5]) + (p.skillXP[6]) + (p.skillXP[7]) + (p.skillXP[8]) + (p.skillXP[9]) + (p.skillXP[10]) + (p.skillXP[11]) + (p.skillXP[12]) + (p.skillXP[13]) + (p.skillXP[14]) + (p.skillXP[15]) + (p.skillXP[16]) + (p.skillXP[17]) + (p.skillXP[18]) + (p.skillXP[19]) + (p.skillXP[20]) + (p.skillXP[21]) + (p.skillXP[22]) + (p.skillXP[23]))+");");
  69.             Misc.println("Values inserted into SQL database");
  70.         } catch (Exception e) {
  71.         Misc.println("Values NOT inserted into SQL database");
  72.             e.printStackTrace();
  73.             return false;
  74.         }
  75.         return true;
  76.     }
  77. }
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