daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package pl.hugozvplayz.hugobans.managers;
  2.  
  3. import java.io.PrintStream;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import org.bukkit.configuration.file.YamlConfiguration;
  10.  
  11. public class MySQL
  12. {
  13.   public MySQL()
  14.   {
  15.     if (FilesManager.ymlconfig.getBoolean("MySQL.Enable")) {
  16.       createTable();
  17.     }
  18.   }
  19.  
  20.   public static String url = "jdbc:mysql://" + FilesManager.ymlconfig.getString("MySQL.Host") + ":" + FilesManager.ymlconfig.getInt("MySQL.Port") + "/";
  21.   public static String database = FilesManager.ymlconfig.getString("MySQL.Database");
  22.   public static String user = FilesManager.ymlconfig.getString("MySQL.User");
  23.   public static String password = FilesManager.ymlconfig.getString("MySQL.Password");
  24.  
  25.   public static void createTable()
  26.   {
  27.     try
  28.     {
  29.       Connection con = DriverManager.getConnection(url + database, user, password);
  30.       Statement st = con.createStatement();
  31.       try
  32.       {
  33.         st.execute("CREATE TABLE IF NOT EXISTS hugoBans(nick CHAR(16), powod VARCHAR(100), czas CHAR(23), admin CHAR(16))");
  34.       }
  35.       catch (SQLException sqle)
  36.       {
  37.         System.out.print(" > Tabela nie zostala stworzona");
  38.       }
  39.       return;
  40.     }
  41.     catch (SQLException sqle)
  42.     {
  43.       System.out.print(" > Nie udalo sie polaczyc z baza danych");
  44.     }
  45.   }
  46.  
  47.   public static void addRecord(String nick, String powod, String czas, String admin)
  48.   {
  49.     try
  50.     {
  51.       Connection con = DriverManager.getConnection(url + database, user, password);
  52.       Statement st = con.createStatement();
  53.       try
  54.       {
  55.         ResultSet rs = st.executeQuery("SELECT * FROM hugoBans WHERE nick='" + nick + "'");
  56.         if (rs.next()) {
  57.           st.execute("UPDATE hugoBans SET powod='" + powod + "', czas='" + czas + "', admin='" + admin + "' WHERE nick='" + nick + "'");
  58.         } else {
  59.           st.execute("INSERT INTO hugoBans VALUES('" + nick + "', '" + powod + "', '" + czas + "', '" + admin + "')");
  60.         }
  61.       }
  62.       catch (SQLException sqle)
  63.       {
  64.         sqle.printStackTrace();
  65.         System.out.print(" > Nie mozna dodac rekordu");
  66.       }
  67.       return;
  68.     }
  69.     catch (SQLException sqle)
  70.     {
  71.       System.out.print(" > Nie udalo sie polaczyc z baza danych");
  72.     }
  73.   }
  74.  
  75.   public static void removeRecord(String nick)
  76.   {
  77.     try
  78.     {
  79.       Connection con = DriverManager.getConnection(url + database, user, password);
  80.       Statement st = con.createStatement();
  81.       try
  82.       {
  83.         st.execute("DELETE FROM hugoBans WHERE nick='" + nick + "'");
  84.       }
  85.       catch (SQLException sqle)
  86.       {
  87.         sqle.printStackTrace();
  88.         System.out.print(" > Nie mozna usunac rekordu");
  89.       }
  90.       return;
  91.     }
  92.     catch (SQLException sqle)
  93.     {
  94.       System.out.print(" > Nie udalo sie polaczyc z baza danych");
  95.     }
  96.   }
  97. }
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