userdao.java

来自「fahirjgjkdfjkl 丰卡时间阿科技安分 发 啊啊啊啊啊」· Java 代码 · 共 77 行

JAVA
77
字号
package com.bookshop.dao;

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

import com.bookshop.dto.User;
import com.bookshop.util.DBManager;



/**
 * @author ������
 *
 */
public class UserDAO {
	public User findUser(String name,String pw){
		User user=null;
		try{
			PreparedStatement pstmt=DBManager.getConnection().prepareStatement("select * from user_tab where name=? and password=?");
			pstmt.setString(1,name);
			pstmt.setString(2,pw);
			ResultSet rs=pstmt.executeQuery();
			while(rs.next()){
				user=new User();
				user.setId(rs.getInt("id"));
				user.setName(rs.getString("name"));
				user.setPassword(rs.getString("password"));
				user.setPrivilege(rs.getInt("privilege"));
				user.setX_id(rs.getInt("x_id"));
				
			}
			
		}catch(SQLException e){e.printStackTrace();}
		return user;
		
	}
	
	public String getUserName(String name){
		String user=null;
		try{
			PreparedStatement pstmt=DBManager.getConnection().prepareStatement("select name from user_tab where name=?");
			pstmt.setString(1,name);
			ResultSet rs=pstmt.executeQuery();
			while(rs.next()){
				user=rs.getString("name");
			}
			
		}catch(SQLException e){e.printStackTrace();}
		return user;
	}
	
	
	public void insertUser(String name,String password){
		try{
			PreparedStatement pstmt=DBManager.getConnection().prepareStatement("insert into user_tab (id,name,password,privilege)values(user_seq.nextval,?,?,0)");
			pstmt.setString(1,name);
			pstmt.setString(2, password);
			pstmt.executeUpdate();

		}catch(SQLException e){e.printStackTrace();}
		
	}
	
	public void updatePw(int id,String pw){
		try{
			PreparedStatement pstmt=DBManager.getConnection().prepareStatement("update user_tab set password=? where id=?");
			pstmt.setString(1,pw);
			pstmt.setInt(2,id);
			pstmt.executeUpdate();

		}catch(SQLException e){e.printStackTrace();}
		
	}
	
}

⌨️ 快捷键说明

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