Advertisement
Guest User

wrapper

a guest
May 8th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package tzt;
  2.  
  3. import java.sql.*;
  4.  
  5. /**
  6. *
  7. * @author pieter
  8. */
  9. public class DBWrapper {
  10. private static Connection connection = null;
  11. private static Statement statement = null;
  12. private static boolean initialized;
  13. public static void initialize() {
  14. if(initialized) {
  15. return;
  16. }
  17.  
  18. try {
  19. Class.forName("com.mysql.jdbc.Driver");
  20. connection = DriverManager.getConnection("jdbc:mysql://localhost/TZT", "root", "");
  21. statement = connection.createStatement();
  22. } catch (Exception e) {
  23. initialized = true;
  24. }
  25. }
  26.  
  27. public static ResultSet executeQuery(String q) {
  28. ResultSet set = null;
  29. try {
  30. set = statement.executeQuery(q);
  31. } catch(Exception e) {}
  32.  
  33. return set;
  34. }
  35.  
  36. public static int executeUpdate(String q) {
  37. int set = 0;
  38. try {
  39. set = statement.executeUpdate(q);
  40. } catch(Exception e) {}
  41.  
  42. return set;
  43. }
  44.  
  45. public static void close() {
  46. try {
  47. statement.close();
  48. connection.close();
  49. } catch (Exception e) {
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement