首页>代码>jsp+servlet+jdbc使用cookie做到系统用户自动登录的java web项目实例>/自动登录/autoLogin/src/com/dao/impl/UserDaoImpl.java
package com.dao.impl;

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

import com.dao.UserDao;
import com.entity.User;
import com.util.DBUtils;

public class UserDaoImpl implements UserDao{

	@Override
	public User getUserByName(String username) {
		Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DBUtils.getConnection();
            ps = con.prepareStatement("SELECT * FROM t_user WHERE username=?");
            ps.setString(1, username);
            rs = ps.executeQuery();
            if (rs.next()) {
                return new User(rs.getInt("id"), rs.getString("username"), rs.getString("password"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
	}
	
	

}
最近下载更多
al4303  LV1 2024年12月3日
wzw77777  LV1 2024年10月8日
1708099240  LV1 2024年9月25日
id20021120  LV1 2024年4月27日
刘亚东  LV1 2024年4月27日
Jim_joker  LV1 2024年4月25日
wu_888  LV1 2024年4月24日
123122a  LV1 2024年4月15日
wl1234  LV1 2024年4月14日
最近浏览更多
小小123 1月9日
暂无贡献等级
scsz234 1月5日
暂无贡献等级
al4303  LV1 2024年12月3日
zzzzzzz31654 2024年11月14日
暂无贡献等级
姚术林 2024年10月12日
暂无贡献等级
wzw77777  LV1 2024年10月8日
1708099240  LV1 2024年9月25日
坚持仙蛊 2024年6月12日
暂无贡献等级
张岱杰 2024年6月7日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友