Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package de.klschlitzohr.main;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7.  
  8. public class MySQL {
  9.  
  10. public static String host = "localhost";
  11. public static String port = "3306";
  12. public static String database = "plot_db";
  13. public static String username = "mysql";
  14. public static String password = "avision";
  15. public static java.sql.Connection con;
  16.  
  17. public static void connect() {
  18. try
  19. {
  20. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
  21. System.out.println("[MySQL] Connected.");
  22. }
  23. catch (SQLException e)
  24. {
  25. System.out.println("[MySQL] Connection failed.");
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. public static void disconnect() {
  31. if (isConnected()) {
  32. try {
  33. con.close();
  34. System.out.println(Utils.prefix + "MYSQL Verbindung izz weg");
  35. } catch (SQLException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41.  
  42. public static boolean isConnected() {
  43. return (con == null ? false : true);
  44.  
  45. }
  46. public static void update(String qry) {
  47. try {
  48. java.sql.PreparedStatement ps = con.prepareStatement(qry);
  49. ps.executeUpdate();
  50. } catch (SQLException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54.  
  55. public static ResultSet getResult(String gry) {
  56. java.sql.PreparedStatement ps;
  57. try {
  58. ps = con.prepareStatement(gry);
  59. return ps.executeQuery();
  60. } catch (SQLException e) {
  61. e.printStackTrace();
  62. }
  63. return null;
  64. }
  65.  
  66. public static java.sql.Connection getConnection() {
  67. return con;
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement