首页>代码>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  LV36 2022年7月31日
最近浏览更多
Yuan_yuan 1月9日
暂无贡献等级
VOEeee 2024年12月17日
暂无贡献等级
暂无贡献等级
zolscy  LV24 2024年11月28日
Yizhuo007 2024年11月26日
暂无贡献等级
ehui33 2024年11月24日
暂无贡献等级
韩同学 2024年11月23日
暂无贡献等级
微信网友_7257882016698368 2024年11月17日
暂无贡献等级
gaochenjun 2024年10月23日
暂无贡献等级
123wwwghh  LV2 2024年9月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友