package com.wang.dao;

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

import com.wang.bean.UserBean;
import com.wang.util.MysqlDbManager;




public class UserDao {
	//登录
	public int loginUser(UserBean user)throws Exception{
		int  res=0;
		
		String sql = null;
		Connection con = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		try {
			con = MysqlDbManager.getConnection();
			sql = "select * from jingtable where loginName='" + user.getLoginName() + "' and loginWord='"+ user.getLoginWord() + "'";
			System.out.println(sql);
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				res++;
				System.out.println("找到了");
			}
		} finally {
			ps.close();
			rs.close();
			MysqlDbManager.closeConnection(con);
		}
		if(res>0){
			return 101;
		}else{
			return 99;
		}
	}
	
	
	
	
	
	//   注册  写入  userbean
	public int insert(UserBean user) throws Exception{
		String sql = null;
		Connection con = null;
		PreparedStatement ps = null;
		int rowCount=0;
		try {
			con = MysqlDbManager.getConnection();
			sql="insert into jingtable(loginName, loginWord) value(?,?)";
			System.out.println(sql);
			ps=con.prepareStatement(sql);
			//设置值
			ps.setString(1, user.getLoginName());
			ps.setString(2, user.getLoginWord());

			//执行
			rowCount=ps.executeUpdate();
			
		}finally{
			ps.close();
			MysqlDbManager.closeConnection(con);;
		}
		if(rowCount>0){
			return 101;//
		}else{
			return 99;
			
		}
	}
	
	
	
	//通过id  查询 userBean
	public UserBean getUserBeanByid( Integer id) throws Exception {
		UserBean resUser = new UserBean();
		String sql = null;
		Connection con = null;
		ResultSet rs = null;
		PreparedStatement ps = null;
		try {
			con = MysqlDbManager.getConnection();
			sql = "select * from jingtable where uid='" + id + "'";
			System.out.println(sql);
			ps = con.prepareStatement(sql);
			rs = ps.executeQuery();
			while (rs.next()) {
				resUser.setUid(rs.getString(1));
				resUser.setLoginName(rs.getString(2));
				resUser.setLoginWord(rs.getString(3));
			}
		} finally {
			ps.close();
			rs.close();
			MysqlDbManager.closeConnection(con);
		}
		return resUser;
	}
	
	
	
	public static void main(String[] args) throws Exception {
//		System.out.println(new TDao().getUserBeanByid(12));
		
		
		UserBean  user=new UserBean("233232", "RRRR");
		int  x=new UserDao().loginUser(user);
		
		System.out.println(x);
	}
}
最近下载更多
王勇是你爹爹  LV1 2021年11月5日
and123456  LV11 2021年10月22日
1420568818  LV7 2021年5月28日
yang2001  LV5 2020年9月16日
aaron2953  LV10 2020年9月1日
hefenyuan91  LV11 2020年6月3日
wo123zhouxiao  LV2 2020年4月22日
9977888  LV1 2020年4月8日
dafengche  LV8 2019年6月27日
232432534254365473  LV5 2019年5月4日
最近浏览更多
Qolmen  LV12 1月9日
张三的MySQL 2023年5月5日
暂无贡献等级
yiming223 2022年12月2日
暂无贡献等级
uni-code_0123  LV1 2022年11月16日
1306878374  LV13 2022年4月11日
1798139161  LV4 2021年12月4日
王勇是你爹爹  LV1 2021年11月5日
and123456  LV11 2021年10月22日
没有鱼  LV3 2021年8月13日
1078859066  LV1 2021年8月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友