package cn.xwkj.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanHandler; import org.apache.commons.dbutils.handlers.ScalarHandler; import cn.xwkj.entity.Admin; import cn.xwkj.util.DataSourceUtils; /** * 超级管理员 * @author 84661 * */ public class AdminDao extends BaseDao{ /** * 校验用户名是否存在 * * @param username * @return * @throws SQLException */ public long checkUsername(String username) throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select count(*) from user where username=?"; long query = (Long) runner.query(sql, new ScalarHandler(), username); return query; } /** * 用户登录的方法 * @param username * @param password * @return * @throws SQLException */ public Admin login(String username, String password) throws SQLException { QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from admin where adminname=? and adminpwd= ?"; return runner.query(sql, new BeanHandler<Admin>(Admin.class), username,password); } // 查询方法(返回结果用集合存储) public List<Admin> list(String sql, Object... param){ List<Admin> list=new ArrayList<Admin>(); ResultSet rs=executeQuery(sql, param); try { while(rs.next()) { Admin a=new Admin(); a.setId(rs.getInt(1)); a.setUsername(rs.getString(2)); a.setPassword(rs.getString(3)); list.add(a); } return list; } catch (SQLException e) { e.printStackTrace(); } finally { closeAll(); } return null; } /** * 添加 */ public int add(String sql, Admin admin) { Object [] param = {admin.getUsername(),admin.getPassword()}; return executeUpdate(sql, param); } }

zhangxinqing1 LV6
2022年10月6日
17693282606 LV12
2022年7月12日
fangen0005 LV25
2022年5月30日
天马行空 LV3
2022年2月7日
dy123123 LV8
2022年1月2日
Tiffany & Co. LV5
2021年12月20日
mwk545924364 LV4
2021年12月9日
凯文 LV5
2021年12月6日
lwp011 LV27
2021年11月5日
maozi0802 LV4
2021年8月6日

Daima000 LV4
2024年12月3日
15719908287 LV9
2024年6月19日
微信网友_6790966844739584 LV5
2024年6月10日
郭宇航裹裹 LV5
2024年6月7日
阿时23428 LV15
2024年3月18日
罗清晨 LV13
2024年2月21日
zyx113
2024年1月5日
暂无贡献等级
asddwh LV13
2023年12月29日
bybingyu LV2
2023年12月20日
2385649653 LV7
2023年12月13日