📄 userdao.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -