返回顶部

一缕半夏微光

温柔半两,从容一生

导航

PreparedStatement的用法

在写精确查找的时候,sql语句用错了,然后查了查PreparedStatement的用法

具体的用法可以参考博文:https://www.cnblogs.com/onmyway20xx/p/4273321.html

 1 String sql= "select * from system where name =?";
 2 Connection conn=Database.getConnection(); 
3
PreparedStatement pstmt = null; 4 ResultSet rs = null; 5 try { 6 pstmt = conn.prepareStatement(sql); 7 pstmt.setString(1, name); 8 rs = pstmt.executeQuery(); 9 while(rs.next()) { 10 String Name=rs.getString("name"); 11 } 12 }

posted on 2020-12-07 18:03  一缕半夏微光  阅读(294)  评论(0编辑  收藏  举报