Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package Ch.Dkrieger.Bedwars.MySQL;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. import Ch.Dkrieger.Bedwars.API.Bedwars;
  10.  
  11. public class MySQL{
  12.  
  13. public static String host = "localhost";
  14. public static String port = "3306";
  15. public static String user = "root";
  16. public static String password = "CXG34twryNE7DME";
  17. public static String database = "DKNick";
  18. public static Connection conn;
  19.  
  20. public static void connect(){
  21. if(!isConnect()){
  22. try {
  23. conn = DriverManager.getConnection("jdbc:mysql://" + host + ":"+port+"/" + database + "?autoReconnect=true",user, password);
  24. System.out.println(Bedwars.prefix+"§eMySQL §7Verbindung erfolgreich aufgebaut!");
  25. } catch (SQLException e) {
  26. System.out.println(Bedwars.prefix+" §eMySQL §7Konnte nicht zur Datenbank verbinden");
  27. System.out.println(Bedwars.prefix+" §eMySQL §7prüfen sie Ihre UserDaten");
  28. }
  29. }
  30. }
  31. public static void disconect(){
  32. if(isConnect()){
  33. try {
  34. conn.close();
  35. System.out.println(Bedwars.prefix+" §§MySQL §7Verbindung wurde geschlossen!");
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41. public static boolean isConnect(){
  42. return (conn==null? false : true);
  43. }
  44. public static void update(String qry){
  45. try{
  46. PreparedStatement ps = conn.prepareStatement(qry);
  47. ps.executeUpdate();
  48. }catch(SQLException e){
  49. e.printStackTrace();
  50. }
  51. }
  52. public static ResultSet getResult(String qry){
  53. try{
  54. PreparedStatement ps = conn.prepareStatement(qry);
  55. return ps.executeQuery();
  56. }catch(SQLException e){
  57. e.printStackTrace();
  58. }
  59. return null;
  60. }
  61. public static Connection getConnecion(){
  62. return conn;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement