Advertisement
Guest User

Untitled

a guest
Nov 28th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public static String username = "root";
  2. public static String passwort = "ByteDanoNiklas15845filoumarkSyloxseineMutteristFett";
  3. public static String host = "localhost";
  4. public static int port = 3306;
  5. public static String database = "Ts3Support";
  6.  
  7. public static Connection con;
  8.  
  9. public static void connect() {
  10. if(!isConnected()) {
  11. try {
  12. con = DriverManager.getConnection("jdbc:mysql://"+host+":"+port+"/"+database, username, passwort);
  13. System.out.println("[MySQL] Die MySQL verbindung ist erfolgt!");
  14. } catch (SQLException e) {
  15. e.printStackTrace();
  16. System.out.println("[MySQL] Es konnte keine Verbindung hergestellt werden..");
  17. }
  18. }
  19. }
  20.  
  21. public static void close() {
  22. if(!isConnected()) {
  23. try {
  24. con.close();
  25. System.out.println("[MySQL] Die Verbindung wurde geschlossen!");
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. System.out.println("[MySQL] Es wurde keine offene Verbindung gefunden!");
  29. }
  30. }
  31. }
  32.  
  33. public static boolean isConnected() {
  34. return con != null;
  35. }
  36.  
  37. public static void update(String qry) {
  38. try {
  39. PreparedStatement ps = con.prepareStatement(qry);
  40. ps.executeUpdate();
  41. } catch (SQLException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. public static ResultSet getResult(String qry) {
  47. try {
  48. PreparedStatement ps = con.prepareStatement(qry);
  49. return ps.executeQuery();
  50. } catch (SQLException e) {
  51. e.printStackTrace();
  52. }
  53. return null;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement