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

📄 userdao.java

📁 BBS系统
💻 JAVA
字号:
package bbs.dao;
import java.lang.annotation.*;
import java.util.ArrayList;

import java.sql.*;

import bbs.bean.useBean;

public class userDao {
	public ArrayList<useBean> getUser(){
		ArrayList<useBean> ar=new ArrayList<useBean>();
		PreparedStatement pt=null;
		ResultSet rs=null;
		
		Connection con=conn.getInstance();
		try {
			pt=con.prepareStatement("select * from BBSUserInfo");
			rs=pt.executeQuery();
			while(rs.next()){
				useBean th=new useBean();
				
				
				th.setIcon(rs.getInt(6));
				th.setPostCnt(rs.getInt(5));
				th.setRewards(rs.getInt(4));
				th.setSex(rs.getString(3));
				th.setUserid(rs.getInt(1));
				th.setUserNickName(rs.getString(2));
				th.setU_name(rs.getString(7));
				th.setU_password(rs.getString(8));
				
				ar.add(th);	
			}
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				pt.close();
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return ar;
	}
	public ArrayList<useBean> getUser(int id){
		ArrayList<useBean> ar=new ArrayList<useBean>();
		PreparedStatement pt=null;
		ResultSet rs=null;
		
		Connection con=conn.getInstance();
		try {
			pt=con.prepareStatement("select * from BBSUserInfo where userid=?");
			pt.setInt(1, id);
			rs=pt.executeQuery();
			while(rs.next()){
				useBean th=new useBean();
				
				
				th.setIcon(rs.getInt(6));
				th.setPostCnt(rs.getInt(5));
				th.setRewards(rs.getInt(4));
				th.setSex(rs.getString(3));
				th.setUserid(rs.getInt(1));
				th.setUserNickName(rs.getString(2));
				th.setU_name(rs.getString(7));
				th.setU_password(rs.getString(8));
				
				ar.add(th);	
			}
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				pt.close();
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return ar;
	}
	public String getUsertwo(int id){
		String ar="";
		PreparedStatement pt=null;
		ResultSet rs=null;
		
		Connection con=conn.getInstance();
		try {
			pt=con.prepareStatement("select * from BBSUserInfo where userid=?");
			pt.setInt(1, id);
			rs=pt.executeQuery();
			while(rs.next()){
				
				
				
				
				ar=rs.getString(2);
				
				
				
				
			}
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally{
			try {
				rs.close();
				pt.close();
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
		return ar;
	}

	

}

⌨️ 快捷键说明

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