Advertisement
Guest User

Untitled

a guest
Jan 7th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package ru.pixelfine.guistats;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. public class Database {
  10.  
  11.     private static Connection connection;
  12.  
  13.     private static void connect() {
  14.         try {
  15.             this.connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/uwbedwars", "root", "HfkIe3i73nM12FkE8pF";
  16.         } catch (SQLException ex) {
  17.             ex.printStackTrace();
  18.         }
  19.     }
  20.  
  21.     public static void close() {
  22.         try {
  23.             this.connection.close();
  24.         } catch (SQLException ex) {}
  25.     }
  26.  
  27.     public static int[] getBWStats(String playerName) {
  28.         int Games = 0, Kills = 0, Wins = 0, Beds = 0;
  29.         try {
  30.             String query = "SELECT `Games`, `Kills`, `Wins`, `Beds` FROM `BedWars` WHERE `Name` LIKE '" + playerName + "'";
  31.             Statement statement = this.getConnection().createStatement();
  32.             ResultSet rs = statement.executeQuery(query);
  33.             Games = rs.getInt(1); Kills = rs.getInt(2); Wins = rs.getInt(3); Beds = rs.getInt(4);
  34.             statement.close(); rs.close();
  35.         } catch (Exception Ex) {
  36.             sqlEx.printStackTrace();
  37.         }
  38.         int stats[] = { Games, Kills, Wins, Beds };
  39.         return stats;
  40.     }
  41.  
  42.     static {
  43.         connect();
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement