Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package resources;
- import Objects.Book;
- import Objects.Branch;
- import Objects.Library;
- import java.sql.*;
- import java.util.ArrayList;
- public class SQLManager {
- private static final String HOST_URL = "jdbc:mysql://localhost:3306/publiclibrary?useSSL=false";
- private static final String HOST_USER = "root";
- private static final String HOST_PASS = "rootroot";
- private static Connection connection = null;
- public static void openConnection() {
- try {
- if (connection == null) {
- connection = DriverManager.getConnection(HOST_URL, HOST_USER, HOST_PASS);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void closeConnection() {
- try {
- if (!connection.isClosed()) {
- connection.close();
- }
- } catch (SQLException ignore) {
- ignore.printStackTrace();
- }
- }
- public static Connection getConnection() {
- if (connection == null) {
- openConnection();
- }
- return connection;
- }
- public static void executeStatement(PreparedStatement statement) {
- try {
- statement.execute();
- } catch (SQLException ignore) {
- ignore.printStackTrace();
- }
- }
- public static ResultSet executeQuery(PreparedStatement statement) {
- try {
- return statement.executeQuery();
- } catch (SQLException ignore) {
- ignore.printStackTrace();
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement