首页>代码>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;
	}
	
	

}
最近下载更多
wu_888  LV1 昨天
123122a  LV1 4月15日
wl1234  LV1 4月14日
ytw123456  LV1 4月12日
黄文雅  LV1 2023年11月21日
jackrako  LV1 2023年11月16日
1403349786  LV1 2023年11月7日
无人区日期QWER  LV1 2023年10月31日
qzhzsgs  LV1 2023年10月22日
GaryWillam  LV1 2023年10月8日
最近浏览更多
wu_888  LV1 昨天
123122a  LV1 4月15日
wl1234  LV1 4月14日
ytw123456  LV1 4月12日
y12wy12wy 2023年12月30日
暂无贡献等级
asddwh  LV12 2023年12月29日
颜菜菜  LV2 2023年12月23日
dev_aheng 2023年12月9日
暂无贡献等级
2271376799 2023年12月2日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友