package common;

import lombok.Getter;

import java.sql.*;

public class DBTool {
    @Getter
    private final Connection conn;
    ResultSet rs;

    public DBTool() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Class.forName("org.sqlite.JDBC");

        //String url = "jdbc:mysql://10.19.38.253:3306/chat?useUnicode=true&characterEncoding=utf-8&useSSL=true";
        String url = "jdbc:sqlite:F:\\Work_Area\\desk\\database\\学习\\java测试数据库\\db_student.db";
        String username = "admin";
        String password = "1227496003131313xY";

        conn = DriverManager.getConnection(url, username, password);
    }

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

    public ResultSet runSQL(PreparedStatement ps) throws SQLException {
        rs = ps.executeQuery();
        return rs;
    }

//    public int doUpdate(String sql) throws SQLException {
//        return stmt.executeUpdate(sql);
//    }

    public void close() throws SQLException {
        if(rs!=null){
            rs.close();
        }
        conn.close();
    }
}
