Advertisement
Guest User

Untitled

a guest
May 29th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. import java.sql.*;
  2. public class highscores extends Thread { //100% Steve.
  3.     public static Connection mySQLConnection;
  4.     public static Statement mySQLStatement;
  5.     public static boolean connectedToMySQL = false;
  6.     public void run() { //Runs in seperate thread now so no hold up at startup.
  7.         try {
  8.             Class.forName("com.mysql.jdbc.Driver");
  9.             String databaseURL = "jdbc:mysql://sql09.freemysql.net:3306/highscores217";
  10.             Connection mySQLConnection = DriverManager.getConnection(databaseURL, "zenscape", "asas69");
  11.             mySQLStatement = mySQLConnection.createStatement();
  12.             System.out.println("Connected to MySQL Database!");
  13.             connectedToMySQL = true;
  14.         } catch (Exception e) {
  15.             e.printStackTrace();
  16.         }
  17.     }
  18.     public static void saveScores(int playerId) {
  19.         Client c = (Client) Server.playerHandler.players[playerId];
  20.        
  21.         if(c == null) {
  22.             return;
  23.         }
  24.         if(c.disconnected) {
  25.             return;
  26.         }
  27.         if(c.playerRights >= 2 && c.playerRights <= 3) {
  28.             return;
  29.         }
  30.         if(c.getTotalLevel() <= 28) {
  31.             return;
  32.         }
  33.         int rights = c.playerRights;
  34.         if(c.donator > 0 && rights != 1) {
  35.             rights = 4;
  36.         }
  37.         if(!c.hasHighscoreEntry) {
  38.             try {
  39.                 mySQLStatement.executeUpdate("INSERT INTO HighScores(playername) VALUES ('" + c.playerName + "')");
  40.                 c.hasHighscoreEntry = true;
  41.             } catch (Exception e) {
  42.                 e.printStackTrace();
  43.             }
  44.         }
  45.         try {
  46.             mySQLStatement.executeUpdate("UPDATE HighScores SET playerrights=" + rights + ", playergetTotalEXP=" + c.getTotalXP() + ", playergetTotalLevel=" + c.getTotalLevel() + ", playerAttack=" + c.playerXP[0] + ", playerDefence=" + c.playerXP[1] + ", playerStrength=" + c.playerXP[2] + ", playerHitpoints=" + c.playerXP[3] + ", playerRanged=" + c.playerXP[4] + ", playerPrayer=" + c.playerXP[5] + ", playerMagic=" + c.playerXP[6] + ", playerCooking=" + c.playerXP[7] + ", playerWoodcutting=" + c.playerXP[8] + ", playerFletching=" + c.playerXP[9] + ", playerFishing=" + c.playerXP[10] + ", playerFiremaking=" + c.playerXP[11] + ", playerCrafting=" + c.playerXP[12] + ", playerSmithing=" + c.playerXP[13] + ", playerMining=" + c.playerXP[14] + ", playerHerblore=" + c.playerXP[15] + ", playerAgility=" + c.playerXP[16] + ", playerThieving=" + c.playerXP[17] + ", playerSlayer=" + c.playerXP[18] + ", playerFarming=" + c.playerXP[19] + ", playerRunecrafting=" + c.playerXP[20] + " WHERE playername='" + c.playerName + "'");
  47.         } catch (Exception e) {
  48.             e.printStackTrace();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement