标签:fss vhd sls epp adl asp ceo spec cfs
基本用法:查找并封装对象与对象集合
public User findUserByNamePassword(String name,String password){ QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from user where name=‘"+name+"‘ and password = ‘"+password+"‘"; User user = null; try { user = runner.query(sql, new BeanHandler<User>(User.class)); } catch (SQLException e) { e.printStackTrace(); } return user; } public List<User> findAllUser(){ QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from user"; List<User> userList = null; try { userList = runner.query(sql, new BeanListHandler<User>(User.class)); } catch (SQLException e) { e.printStackTrace(); } return userList; }
//获得全部的用户条数,返回一个整数 public int getTotalCount() throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select count(*) from user"; Long query = (Long) runner.query(sql, new ScalarHandler()); return query.intValue(); }
标签:fss vhd sls epp adl asp ceo spec cfs
原文地址:http://www.cnblogs.com/qlqwjy/p/7551032.html