首页 > 其他 > 详细

PreparedStatmen局处理语句

时间:2021-03-01 21:53:10      阅读:36      评论:0      收藏:0      [点我收藏+]

 

public class PreparedStatmentDemo {
    public static void main(String[] args) {
        try {
            //var:定义变量
        var c =new DbUtil().getConn();
            PreparedStatement ps = c.prepareStatement("select *from stu");
            ResultSet rs =ps.executeQuery();
            while(rs.next()){
                    System.out.print(rs.getInt("id"));
                    System.out.print(",");
                    System.out.print(rs.getString("name"));
                    System.out.println(rs.getString("score"));

                    //时间
//                    Date bir = rs.getDate("birth");
//                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    System.out.println(sdf.format(bir));

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}

链接数据库类

  private String driver = "com.mysql.cj.jdbc.Driver";
    private String url = "jdbc:mysql:/db1";
    private String user = "aa";
    private String password = "";
    private Connection conn = null;//Connection链接语句

    public DbUtil() {
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

PreparedStatmen局处理语句

原文:https://www.cnblogs.com/Gu1015/p/14465224.html

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