package com.example;

import java.sql.*;

public class Jdbc {
    private Connection conn;
    private Statement stmt;
    private ResultSet rs;

    Jdbc(){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String password = "root";
            String username = "root";
            conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/su?useSSL=false&serverTimezone=UTC", username, password);
            stmt=conn.createStatement();
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }
    }

    public ResultSet query(String sql) throws SQLException {
        rs=stmt.executeQuery(sql);
        return rs;
    }

    public void update(String sql) throws SQLException {
        stmt.executeUpdate(sql);
    }
    public void close() throws SQLException {
        if(rs!=null){
            rs.close();
        }
        if(stmt!=null){
            stmt.close();
        }
        if(conn!=null){
            conn.close();
        }
    }
}
