Advertisement
Guest User

Untitled

a guest
Aug 29th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 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 urlbase, String host, String database, String username, String password) {
  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. //connection
  27. public void connect(){
  28. if(!isConnected()){
  29. try{
  30. con = DriverManager.getConnection(urlbase + host + "/" + database, username, password);
  31. System.out.println("Connection etablie !");
  32. }catch (SQLException e) {
  33. e.printStackTrace();
  34. System.out.println("Accès Refusé");
  35. }
  36.  
  37. }
  38. }
  39.  
  40. //public void disconnect(){
  41. //if(isConnected()){
  42. //try{
  43. //con.close();
  44. //System.out.print("Connection Fermée !");
  45. //}catch (SQLException e){
  46. // e.printStackTrace();
  47. // }
  48. // }
  49. //}
  50.  
  51. private boolean isConnected() {
  52. return (con != null);
  53. }
  54. public Connection getConnection(){
  55. return con;
  56. }
  57.  
  58.  
  59. public boolean getReport(Player player){
  60. try{
  61. PreparedStatement q = (PreparedStatement) con.prepareStatement("SELECT * FROM report WHERE uuid = ?");
  62. q.setString(1, player.getUniqueId().toString());
  63. ResultSet resultat = q.executeQuery();
  64. boolean getReport = resultat.next();
  65. q.close();
  66. return getReport;
  67. }catch (SQLException e){
  68. e.printStackTrace();
  69. }
  70. return false;
  71. }
  72.  
  73.  
  74. public void postReport(Player player, String arg){
  75.  
  76.  
  77. try{
  78. PreparedStatement q = (PreparedStatement) con.prepareStatement("INSERT INTO report (uuid, reason) VALUES (?,?)");
  79. q.setString(1, player.getUniqueId().toString());
  80. q.setString(2, arg);
  81. q.execute();
  82. }catch (SQLException e){
  83. e.printStackTrace();
  84. }
  85. }
  86.  
  87. public int getHowManyReport(Player player){
  88. return 0;
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement