JDBC(待更新)

步骤

建立数据库连接

protected Connection coon = null;
    protected PreparedStatement pstmt = null;
    protected ResultSet rs = null;

    public Connection getConnection() {
        try {
            String url = "jdbc:mysql://localhost:3306/my_db?useUnicode=true&characterEncoding=utf-8";
            String user = "sa";
            String password = "123456";
            coon = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return coon;
    }

    public void closeAll(Connection coon, PreparedStatement pstmt, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (coon != null) {
                coon.close();
            }
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

查询语句

posted @ 2021-01-10 23:12  一个经常掉线的人  阅读(81)  评论(0)    收藏  举报