Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package osps;
  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. import osps.model.players.Player;
  10. import osps.model.players.PlayerHandler;
  11.  
  12. public class PlayersOnline {
  13.  
  14. public static Connection con = null;
  15. public static Statement stm;
  16.  
  17. public static void createCon() {
  18. try {
  19. Class.forName("com.mysql.jdbc.Driver").newInstance();
  20. con = DriverManager.getConnection("jdbc:mysql://212.1.208.242/ospsorg_world", "ospsorg_julius", "ballehora");
  21. stm = con.createStatement();
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. }
  25. }
  26.  
  27. public static ResultSet query(String s) throws SQLException {
  28. try {
  29. if (s.toLowerCase().startsWith("select")) {
  30. ResultSet rs = stm.executeQuery(s);
  31. return rs;
  32. } else {
  33. stm.executeUpdate(s);
  34. }
  35. return null;
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. return null;
  40. }
  41.  
  42. public static void destroyCon() {
  43. try {
  44. stm.close();
  45. con.close();
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. }
  49. }
  50.  
  51. public static boolean offline(Player c) {
  52. try {
  53. query("DELETE FROM `online` WHERE id = 1;");
  54.  
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. return false;
  58. }
  59. return true;
  60. }
  61.  
  62. public static boolean online(Player c) {
  63. try {
  64. query("REPLACE INTO `online` (id, currentlyonline) VALUES('1','"+PlayerHandler.getPlayerCount()+"');");
  65.  
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. return false;
  69. }
  70. return true;
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement