blogger

点滴记忆

使用emlog搭建的站点

文章110

评论3

用户管理系统之用户注册
package com.ngl.um.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.ngl.um.bean.UserBean;
import com.ngl.um.dao.ModifySelfInfoDao;
import com.ngl.um.util.DBUtil;

/**
 * 负责修改个人信息的Dao类
 * 
 * @author 卢飞飞
 * 
 */
public class ModifySelfInfoDaoImpl implements ModifySelfInfoDao {

	/**
	 * 负责修改个人信息的方法
	 * 
	 * @param userVO
	 *            待修改的个人信息,封装在UserBean中
	 * @return 返回封装有修改后的个人信息的UserBean
	 */
	public UserBean updateOfModifySelfInfo(UserBean userVO) {

		boolean flag = false;
		DBUtil dbUtil = new DBUtil();
		Connection conn = dbUtil.getConnection();
		PreparedStatement pstmt = null;

		String sql = "UPDATE user SET username=?,password=?,"
				+ "gender=?,birthday=?,email=?,"
				+ "hobby=?,remark=?,usertype=? WHERE userid=?";

		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, userVO.getUsername());
			pstmt.setString(2, userVO.getPassword());
			pstmt.setString(3, userVO.getGender());
			pstmt.setDate(4, userVO.getBirthday());
			pstmt.setString(5, userVO.getEmail());
			pstmt.setString(6, userVO.getHobby());
			pstmt.setString(7, userVO.getRemark());
			pstmt.setString(8, userVO.getUsertype());
			pstmt.setString(9, userVO.getUserid());

			if (pstmt.executeUpdate() == 1) {
				flag = true;
				conn.commit();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			flag = false;
			try {
				conn.rollback();
			} catch (SQLException ex) {
				ex.printStackTrace();
			}
		} finally {
			try {
				pstmt.close();
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if (flag) {
			return userVO;
		} else {
			return null;
		}
	}

}
评论(0)

© 2018  点滴记忆  · emlog
  Design by 往记