📄 operator.java
字号:
pstmt=con.prepareStatement("delete from admin where adminId=?");
pstmt.setString(1,adminId);
pstmt.execute();
str="sucess";
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//是否存在班干编号
public boolean existMonitor(Monitor monitor) {
try {
String monitorAdminId = monitor.getMonitorAdminId();
PreparedStatement pstmt = con.prepareStatement(
"select monitorAdminId from monitorAdmin where monitorAdminId='" +
monitorAdminId + "'");
ResultSet rst = pstmt.executeQuery();
if (rst.next()) {
return true;
}
} catch (Exception ex) {
return false;
}
return false;
}
//添加班干
public String addMonitor(Monitor monitor)
{
PreparedStatement pstmt=null;
String str="";
try
{
if (existMonitor(monitor)) {
return "exist"; //存在
}
pstmt=con.prepareStatement("insert into monitorAdmin values(?,?,?,?)");
pstmt.setString(1,monitor.getMonitorAdminId());
pstmt.setString(2,monitor.getMonitorName());
pstmt.setString(3,monitor.getClassName());
pstmt.setString(4,monitor.getMonitorAdminPassword());
pstmt.execute();
str="sucess";
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
public String deleteMonitor(String monitorAdminId)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("delete from monitorAdmin where monitorAdminId=?");
pstmt.setString(1,monitorAdminId);
pstmt.execute();
str="sucess";
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//
public ResultSet executeQuery(String sql)
{
Statement stmt=null;
ResultSet rst=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst=stmt.executeQuery(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
return rst;
}
//
public void executeUpdate(String sql)
{
Statement stmt=null;
try{
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(sql);
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
}
//
//更改密码
public String modifyPassword(String adminId,String oldPassword,String newPassword)
{
myclass.conn.MD5Encode md5=new myclass.conn.MD5Encode();
oldPassword=md5.MD5Encodes(oldPassword);
newPassword=md5.MD5Encodes(newPassword);
PreparedStatement pstmt=null;
ResultSet rst=null;
String str="";
try{
rst=executeQuery("select adminId from admin where adminId='"+adminId+"' and adminPassword='"+oldPassword+"'");
if(!rst.next()){
str="wrong";//密码错误
}
else
{
pstmt=con.prepareStatement("update admin set adminPassword=? where adminId=?");
pstmt.setString(1,newPassword);
pstmt.setString(2,adminId);
pstmt.execute();
str="sucess";//密码修改成功
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";//密码修改失败
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//更改
public String modifyMonitorPassword(String monitorAdminId,String oldPassword,String newPassword)
{
myclass.conn.MD5Encode md5=new myclass.conn.MD5Encode();
oldPassword=md5.MD5Encodes(oldPassword);
newPassword=md5.MD5Encodes(newPassword);
PreparedStatement pstmt=null;
ResultSet rst=null;
String str="";
try{
rst=executeQuery("select monitorAdminId from monitorAdmin where monitorAdminId='"+monitorAdminId+"' and monitorAdminPassword='"+oldPassword+"'");
if(!rst.next()){
str="wrong";//密码错误
}
else
{
pstmt=con.prepareStatement("update monitorAdmin set monitorAdminPassword=? where monitorAdminId=?");
pstmt.setString(1,newPassword);
pstmt.setString(2,monitorAdminId);
pstmt.execute();
str="sucess";//密码修改成功
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";//密码修改失败
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//系统管理员更改密码
public String modifySystemPassword(String adminId,String oldPassword,String newPassword)
{
myclass.conn.MD5Encode md5=new myclass.conn.MD5Encode();
oldPassword=md5.MD5Encodes(oldPassword);
newPassword=md5.MD5Encodes(newPassword);
PreparedStatement pstmt=null;
ResultSet rst=null;
String str="";
try{
rst=executeQuery("select systemAdminId from systemAdmin where systemAdminId='"+adminId+"' and systemAdminPassword='"+oldPassword+"'");
if(!rst.next()){
str="wrong";//密码错误
}
else
{
pstmt=con.prepareStatement("update systemAdmin set systemAdminPassword=? where systemAdminId=?");
pstmt.setString(1,newPassword);
pstmt.setString(2,adminId);
pstmt.execute();
str="sucess";//密码修改成功
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";//密码修改失败
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//所有班级
public String getAllClass()
{
PreparedStatement pstmt = null;
ResultSet rst = null;
StringBuffer sBuf=new StringBuffer();
try {
pstmt = con.prepareStatement("select distinct className from banji");
rst = pstmt.executeQuery();
while(rst.next()) {
String className= rst.getString("className");
sBuf.append("<option value='"+className+"'>"+className+"</option>\n");
}
}
catch (SQLException ex) {
ex.printStackTrace();
return "";
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return sBuf.toString();
}
//关闭
public void close()
{
try{
if(con!=null){
con.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
/*
public static void main(String[] args) {
Operator operator = new Operator();
Monitor officer=operator.queryMonitor("admin","363b122c528f54df4a0446b6bab05515");
System.out.println("uid " + officer.getReturnValue());
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -