Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package server.model.players;
  2.  
  3. import java.sql.*;
  4. import server.model.players.*;
  5.  
  6. public class clanocideTeams {
  7.  
  8.     public static Connection connection;
  9.     public static Statement stmt;
  10.     public static ResultSet results;
  11.     public static boolean connected;
  12.  
  13.     public static String Host = "jdbc:mysql://HOST/DATABASE";
  14.     public static String User = "USERNAME";
  15.     public static String Pass = "PASSWORD";
  16.    
  17.     private Client c;
  18.    
  19.    
  20.     /**
  21.      * Creates the connection to the database
  22.      */
  23.  
  24.     public static void connectToDatabase() {
  25.         try {
  26.  
  27.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  28.             Connection con = DriverManager.getConnection(Host, User, Pass);
  29.             stmt = con.createStatement();
  30.             connected = true;
  31.  
  32.         } catch (Exception e) {
  33.             connected = false;
  34.             e.printStackTrace();
  35.  
  36.         }
  37.     }
  38.    
  39.     /**
  40.      * destroys the connection to the database
  41.      */
  42.    
  43.     public static void destroyCon() {
  44.         try {
  45.  
  46.             stmt.close();
  47.             connection.close();
  48.  
  49.         } catch (Exception e) {
  50.  
  51.         }
  52.     }
  53.  
  54.     public static ResultSet query(String s) throws SQLException {
  55.         try {
  56.             if (s.toLowerCase().startsWith("select")) {
  57.                 ResultSet rs = stmt.executeQuery(s);
  58.                 return rs;
  59.             } else {
  60.                 stmt.executeUpdate(s);
  61.             }
  62.             return null;
  63.         } catch (Exception e) {
  64.             destroyCon();
  65.             connectToDatabase();
  66.  
  67.         }
  68.         return null;
  69.     }
  70.    
  71.     public static boolean saveClanocideKills(Client client) {
  72.         try {
  73.             //TODO
  74.            
  75.         } catch (Exception e) {
  76.             //e.printStackTrace();
  77.             return false;
  78.         }
  79.         return true;
  80.     }
  81.    
  82.     public static boolean saveClanocideDeaths(Client client) {
  83.         try {
  84.             //TODO
  85.            
  86.         } catch (Exception e) {
  87.             //e.printStackTrace();
  88.             return false;
  89.         }
  90.         return true;
  91.     }
  92.    
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement