首页 > 数据库技术 > 详细

JDBC

时间:2021-01-10 23:45:22      阅读:40      评论:0      收藏:0      [点我收藏+]

步骤

技术分享图片

建立数据库连接

技术分享图片

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();
        }
    }

查询语句

技术分享图片

JDBC

原文:https://www.cnblogs.com/OfflineBoy/p/14260104.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!