Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class MySQL {
  2.  
  3. public static String host;
  4. public static String port;
  5. public static String database;
  6. public static String username;
  7. public static String password;
  8. public static Connection con;
  9.  
  10. public static void connect() {
  11. if (!isConnected()) {
  12. try {
  13. con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username,
  14. password);
  15. System.out.println("[MySQL] Verbindung aufgebaut!");
  16. } catch (SQLException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. }
  21.  
  22. public static void disconnect() {
  23. if (isConnected()) {
  24. try {
  25. con.close();
  26. System.out.println("[MySQL] Verbindung geschlossen!");
  27. } catch (SQLException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31.  
  32. }
  33.  
  34. public static boolean isConnected() {
  35. return (con == null ? false : true);
  36. }
  37.  
  38. public static void update(String qry) {
  39. try {
  40. PreparedStatement ps = con.prepareStatement(qry);
  41. ps.executeUpdate();
  42. } catch (SQLException e) {
  43. e.printStackTrace();
  44. }
  45.  
  46. }
  47.  
  48. public static ResultSet getResult(String qry){
  49. try{
  50. PreparedStatement ps = con.prepareStatement(qry);
  51. return ps.executeQuery();
  52. }catch (SQLException e){
  53. e.printStackTrace();
  54. }
  55. return null;
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement