⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userdaoimpl.java

📁 使用JSP+MSSQL开发的在线通讯录系统.包含源码
💻 JAVA
字号:
package com.e98.addressbook.dao.impl;

import com.e98.addressbook.dao.UserDao;
import com.e98.addressbook.entity.Users;
import com.e98.addressbook.common.*;
import java.sql.*;

public class UserDaoImpl implements UserDao {

	public Users validUser(String userName, String password) {
		Users user = null;
		ResultSet rs = null;
		PreparedStatement pst = null;
		Connection conn = ConnectionManager.getConn();
		String sql = "select * from users where userName=? and password=?";
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, userName);
			pst.setString(2, password);
			rs = pst.executeQuery();
			if (rs.next()) {
				user = new Users();
				user.setPassword(rs.getString("password"));
				user.setRealName(rs.getString("realName"));
				user.setSex(rs.getString("sex"));
				user.setUserId(rs.getInt("userId"));
				user.setUserName(rs.getString("userName"));
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			ConnectionManager.closeResultSet(rs);
			ConnectionManager.closePreparedStatement(pst);
			ConnectionManager.colseConnection(conn);
		}
		return user;

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -