📄 operatordao.java~34~
字号:
package com.cdaccp.dao;
import com.util.DBAccess;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.cdaccp.entity.Operator;
public class OperatorDAO {
public OperatorDAO() {
}
/**
* 根据操作员的编号和密码验证该操作员是否有效
* @param id int 操作员编号
* @param password String 操作员密码
* @return boolean 有效则返回真,否则返回假
*/
public static boolean verifyUser(int id, String password) {
/*
* 请完成登录验证代码
*/
return true;
}
/**
* 根据操作员的编号或的该操作员的其他信息
* @param id int 参数为操作员的Id号
* @return Operator 返回一个Operator(操作员)对象
*/
public static Operator loadById(int id) {
Operator op = null;
Connection conn = DBAccess.getConnection();
PreparedStatement pstmt = null;
String sql = "select name,pwd from operator where id=?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, id);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
op = new Operator();
op.setName(rs.getString("name"));
op.setPassword(rs.getString("pwd"));
op.setId(id);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
DBAccess.closeConnection(conn);
}
return op;
}
/**
* 添加操作员
* @param operator Operator 参数为一个Operator(操作员)对象
* @return boolean 成功返回真,否则返回假
*/
public static boolean addOperator(Operator operator) {
return false;
}
public static boolean ChangePassword(int id,String pwd){
Connection con = DBAccess.getConnection();
PreparedStatement pst = null;
String sql = "update operator set pwd = ? where id = ?";
try {
pst = con.prepareStatement(sql);
pst.setInt(1,id);
pst.setString(2,pwd);
int i = pst.executeUpdate();
if( i > 0 ){
return true;
}
}
catch (Exception ex) {
ex.printStackTrace();
}finally{
DBAccess.closeConnection(con);
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -