首页>代码>jsp+servlet开发java web个人日记本系统>/Diary/src/com/wishwzp/dao/UserDao.java
package com.wishwzp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.wishwzp.model.User;
import com.wishwzp.util.MD5Util;
import com.wishwzp.util.PropertiesUtil;

public class UserDao {

	/**
	 * 登录验证
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public User login(Connection con,User user)throws Exception{
		User resultUser=null;
		String sql="select * from t_user where userName=? and password=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, user.getUserName());
		pstmt.setString(2, MD5Util.EncoderPwdByMd5(user.getPassword()));
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			resultUser=new User();
			resultUser.setUserId(rs.getInt("userId"));
			resultUser.setUserName(rs.getString("userName"));
			resultUser.setPassword(rs.getString("password"));
			resultUser.setNickName(rs.getString("nickName"));
			resultUser.setImageName(PropertiesUtil.getValue("imageFile")+rs.getString("imageName"));
			resultUser.setMood(rs.getString("mood"));
		}
		return resultUser;
	}
	
	/**
	 * 个人资料修改
	 * @param con
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public int userUpdate(Connection con,User user)throws Exception{
		String sql="update t_user set nickName=?,imageName=?,mood=? where userId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, user.getNickName());
		pstmt.setString(2, user.getImageName());
		pstmt.setString(3, user.getMood());
		pstmt.setInt(4, user.getUserId());
		return pstmt.executeUpdate();
	}
}
最近下载更多
hanweinan6  LV13 2024年10月9日
waitingforyou  LV20 2022年10月20日
是你爸爸啊100  LV5 2022年8月5日
xuweisong2010  LV28 2022年6月7日
ming_123_9715  LV23 2021年12月26日
yellowfor  LV8 2021年12月24日
dcdc12  LV6 2021年12月21日
 LV6 2021年11月8日
xbjzc123  LV5 2021年10月14日
内拉组里  LV2 2021年10月13日
最近浏览更多
ma406805131  LV19 2024年12月19日
214329 2024年11月29日
暂无贡献等级
张泽帅  LV6 2024年10月18日
暂无贡献等级
Liang朝伟  LV1 2024年1月6日
asddwh  LV13 2023年12月29日
abandan  LV4 2023年11月6日
微信网友_6602457430806528  LV6 2023年10月17日
qazws123  LV1 2023年6月8日
846488283  LV4 2023年5月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友