首页>代码>jsp+servlet+c3p0开发传智播客电子书城项目源码,包含ppt>/(2019-5-16,第二个项目)传智书城项目资料汇总/(项目源码)itcaststore/src/cn/itcast/itcaststore/dao/UserDao.java
package cn.itcast.itcaststore.dao;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import cn.itcast.itcaststore.domain.User;
import cn.itcast.itcaststore.utils.DataSourceUtils;

public class UserDao {
	// 添加用户
	public void addUser(User user) throws SQLException {
		String sql = "insert into user(username,password,gender,email,telephone,introduce,activecode) values(?,?,?,?,?,?,?)";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		int row = runner.update(sql, user.getUsername(), user.getPassword(),
				user.getGender(), user.getEmail(), user.getTelephone(),
				user.getIntroduce(), user.getActiveCode());
		if (row == 0) {
			throw new RuntimeException();
		}
	}

	// 根据激活码查找用户
	public User findUserByActiveCode(String activeCode) throws SQLException {
		String sql = "select * from user where activecode=?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanHandler<User>(User.class), activeCode);

	}

	// 激活用戶
	public void activeUser(String activeCode) throws SQLException {
		String sql = "update user set state=? where activecode=?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		runner.update(sql, 1, activeCode);
	}
	
	//根据用户名与密码查找用户
	public User findUserByUsernameAndPassword(String username, String password) throws SQLException {
		String sql="select * from user where username=? and password=?";
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		return runner.query(sql, new BeanHandler<User>(User.class),username,password);
	}

}
最近下载更多
周敏国  LV9 2023年8月19日
Gjc175636312  LV2 2023年4月20日
xiaoadmin  LV1 2023年1月29日
Jiang_jiang5  LV1 2023年1月9日
zxwzxwz  LV2 2023年1月2日
Ada-Lilith  LV1 2022年12月7日
zsj45655  LV1 2022年10月4日
ldm654123  LV3 2022年10月1日
18356557758  LV5 2022年9月15日
onemee  LV35 2022年7月31日
最近浏览更多
aries03302 4月10日
暂无贡献等级
暂无贡献等级
张庆余 4月9日
暂无贡献等级
暂无贡献等级
tyokok 1月22日
暂无贡献等级
程星龄 1月20日
暂无贡献等级
MOB12138 1月20日
暂无贡献等级
gpnuxy 1月14日
暂无贡献等级
9898989 2023年12月30日
暂无贡献等级
查询图片 2023年12月29日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友