Guest User

Untitled

a guest
Sep 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Find List of Players That use Same IP in MySql DataBase in Java
  2. public boolean checksameip(Player player, String IP){
  3. boolean ret = false;
  4. String playername = player.getName();
  5. try{
  6. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/WebCom", "root", "MyPW");
  7.  
  8.  
  9. Statement stmt = (Statement) con.createStatement();
  10.  
  11. ResultSet rs = stmt.executeQuery("SELECT PlayerName FROM IPDataBase WHERE IP='"+IP+"'");
  12.  
  13. if(rs.next()){
  14. //there are results
  15.  
  16. //have no clue what to put here :S
  17.  
  18.  
  19. }else{
  20.  
  21. ret = false;
  22. }
  23.  
  24.  
  25. con.close();
  26.  
  27. }catch(Exception e){
  28.  
  29. logm("Could Not Send Data To MYSQL DATABASE SERVER");
  30. }
  31.  
  32. return ret;
  33. }
  34.  
  35. public String[] getPlayersWithIP(String ip) {
  36. try{
  37. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/WebCom", "root", "MyPW");
  38. Statement stmt = (Statement) con.createStatement();
  39. ResultSet rs = stmt.executeQuery("SELECT PlayerName FROM IPDataBase WHERE IP='"+ip+"'");
  40. HashSet<String> result = new HashSet<String>();
  41. int i=0;
  42. while(rs.next()){
  43. result.add(getString("PlayerName"));
  44. }
  45. con.close();
  46. return result.toArray(new String[0]);
  47. }catch(Exception e){
  48. logm("Could Not Send Data To MYSQL DATABASE SERVER");
  49. return new String[0];
  50. }
  51. }
Add Comment
Please, Sign In to add comment