Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. package destinymod.MySQL;
  2.  
  3.  
  4.  
  5. import org.bukkit.entity.Player;
  6.  
  7. import java.sql.*;
  8.  
  9. public class MySql {
  10.  
  11. private String urlbase,host,database,username,password;
  12.  
  13. public MySql(String s) {
  14. this.urlbase = urlbase;
  15. this.host = host;
  16. this.database = database;
  17. this.username = username;
  18. this.password = password;
  19.  
  20. }
  21.  
  22.  
  23. public Connection con;
  24.  
  25.  
  26.  
  27. //connection
  28. public void connect(){
  29. if(!isConnected()){
  30. try{
  31. con = DriverManager.getConnection(urlbase + host + "/" + database, username, password);
  32. System.out.println("Connection etablie !");
  33. }catch (SQLException e) {
  34. e.printStackTrace();
  35. System.out.println("Accès Refusé");
  36. }
  37.  
  38. }
  39. }
  40.  
  41. //public void disconnect(){
  42. //if(isConnected()){
  43. //try{
  44. //con.close();
  45. //System.out.print("Connection Fermée !");
  46. //}catch (SQLException e){
  47. // e.printStackTrace();
  48. // }
  49. // }
  50. //}
  51.  
  52. private boolean isConnected() {
  53. return (con != null);
  54. }
  55. public Connection getConnection(){
  56. return con;
  57. }
  58.  
  59.  
  60. public boolean getReport(Player player){
  61. try{
  62. PreparedStatement q = (PreparedStatement) con.prepareStatement("SELECT * FROM report WHERE uuid = ?");
  63. q.setString(1, player.getUniqueId().toString());
  64. ResultSet resultat = q.executeQuery();
  65. boolean getReport = resultat.next();
  66. q.close();
  67. return getReport;
  68. }catch (SQLException e){
  69. e.printStackTrace();
  70. }
  71. return false;
  72. }
  73.  
  74.  
  75. public void postReport(Player player, String arg){
  76.  
  77.  
  78. try{
  79. PreparedStatement q = (PreparedStatement) con.prepareStatement("INSERT INTO report (uuid, reason) VALUES (?,?)");
  80. q.setString(1, player.getUniqueId().toString());
  81. q.setString(2, arg);
  82. q.execute();
  83. }catch (SQLException e){
  84. e.printStackTrace();
  85. }
  86. }
  87.  
  88. public int getHowManyReport(Player player){
  89. return 0;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement