数据库中的DbUtils
public class TestDbutils {
public static void main(String[] args) throws SQLException {
// String sql = "insert into admin values(005,‘风声鹤唳‘,‘5555‘)";
// String sql = "insert into admin values(?,?,?)";
// String upt = "update admin set name = ? where aid = ?";
// String del = "delete admin where aid = ?";
QueryRunner qr = new QueryRunner(DataSourceUtils.getDatasSource());
// qr.update(sql);
// qr.update(sql,006,"鹤立鸡群","6666");
// qr.update(upt,"鹤立鸡群",005);
// qr.update(del,006);
// String sel = "select * from admin where aid = ?";
// Admin admin = qr.query(sel, new BeanHandler<Admin>(Admin.class),005);
// System.out.println(admin.getAid()+" "+admin.getName()+" "+admin.getPwd());
// String sel = "select * from admin";
// List<Admin> admins = qr.query(sel, new BeanListHandler<Admin>(Admin.class));
// for(Admin admin:admins){
// System.out.println(admin.getAid()+" "+admin.getName()+" "+admin.getPwd());
// }
String sel = "select admin.*,priv.* from admin,priv where admin.pid = priv.pid";
List<Map<String,Object>> mm = qr.query(sel, new MapListHandler());
for(Map<String,Object> mo : mm)
{
System.out.println(mo.get("aid") + " "
+ mo.get("name")+" "+mo.get("pwd")+" "
+ mo.get("pid")+" "+mo.get("pname"));
}
}
}
本文出自 “InProvence” 博客,谢绝转载!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。