Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. package resources;
  2.  
  3. import Objects.Book;
  4. import Objects.Branch;
  5. import Objects.Library;
  6.  
  7. import java.sql.*;
  8. import java.util.ArrayList;
  9.  
  10. public class SQLManager {
  11.  
  12. private static final String HOST_URL = "jdbc:mysql://localhost:3306/publiclibrary?useSSL=false";
  13. private static final String HOST_USER = "root";
  14. private static final String HOST_PASS = "rootroot";
  15.  
  16. private static Connection connection = null;
  17.  
  18. public static void openConnection() {
  19. try {
  20.  
  21. if (connection == null) {
  22. connection = DriverManager.getConnection(HOST_URL, HOST_USER, HOST_PASS);
  23. }
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28.  
  29. public static void closeConnection() {
  30. try {
  31. if (!connection.isClosed()) {
  32. connection.close();
  33. }
  34. } catch (SQLException ignore) {
  35. ignore.printStackTrace();
  36. }
  37. }
  38.  
  39. public static Connection getConnection() {
  40. if (connection == null) {
  41. openConnection();
  42. }
  43. return connection;
  44. }
  45.  
  46. public static void executeStatement(PreparedStatement statement) {
  47. try {
  48. statement.execute();
  49. } catch (SQLException ignore) {
  50. ignore.printStackTrace();
  51. }
  52. }
  53.  
  54. public static ResultSet executeQuery(PreparedStatement statement) {
  55. try {
  56. return statement.executeQuery();
  57. } catch (SQLException ignore) {
  58. ignore.printStackTrace();
  59. }
  60. return null;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement