基础类部分代码:
/*
* DataBase.java
*
* Created on 2006年6月15日, 下午1:00
*/
package personadmin;
import java.beans.*;
import java.io.Serializable;
import java.sql.*;
/**
* @author ibm
*/
public class DataBase extends Object implements Serializable
{
//by terry
public Connection con;
public java.sql.Statement sql;
public ResultSet rs=null;
public String sqlStr;
public DataBase()
{
this.connect();
this.sqlStr = "";
}
public boolean connect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try
{
con = DriverManager.getConnection("jdbc:odbc:stuinfo","","");
sql = con.createStatement();
}
catch (SQLException ex)
{
return false;
}
return true;
}
}
/*
* ChineseProcess.java
*
* Created on 2006年6月16日, 下午10:54
*/
package personadmin;
import java.beans.*;
import java.io.Serializable;
/**
* @author ibm
*/
public class ChineseProcess extends Object implements Serializable
{
/* private String older;
public ChineseProcess()
{
this.older = "";
}
public void setolder(String temp)
{
this.older = temp;
}*/
public String formatchange(String temp)throws Exception
{
byte b[] = temp.getBytes("ISO-8859-1");
String fuck = new String(b);
// temp = new String(b);
return fuck;
}
}
/*
* ChangePassword.java
*
* Created on 2006年6月15日, 下午8:07
*/
package personadmin;
import java.beans.*;import java.io.Serializable;import personadmin.DataBase;import java.sql.*;/** * @author ibm */public class ChangePassword extends Object implements Serializable { private String name; //用户名 private String type; //用户类型 private String oldpassword; //旧密码 private String newpassword; //新密码 private String affirmpassword; //确认密码 private DataBase db; //数据库处理 public ChangePassword() { this.name = ""; this.type = ""; this.oldpassword = ""; this.newpassword = ""; this.affirmpassword = ""; this.db = new DataBase(); } public void setName(String temp) { this.name = temp; } public void setType(String temp) { this.type = temp; } public void setoldpassword(String temp) { this.oldpassword = temp; } public void setnewpassword(String temp) { this.newpassword = temp; } public void setaffirmpassword(String temp) { this.affirmpassword = temp; } public String getName() { return this.name; } public String getType() { return this.type; } public String getoldpassword() { return this.oldpassword; } public String getnewpassword() { return this.newpassword; } public String getaffirmpassword() { return this.affirmpassword; } public boolean justicenew() //判断两个密码是否相等 { return this.newpassword.equals(this.affirmpassword); } public boolean justiceolder(String session_password) //判断旧密码是否输入是否正确 { //temp从session获得 return this.oldpassword.equals(session_password); } //temp用户旧密码 public boolean findOlder(String session_password) //获得修改密码 { if (this.justicenew() && this.justiceolder(session_password)) //如果两个密码相等,并且旧密码也是正确的 { if (this.type.equals("administrator")) //管理员身份 { this.db.sqlStr = "update admininfo set adm_password = '"+this.newpassword+"' where adm_name = '"+this.name+"'"; } else if (this.type.equals("teacher")) //老师身份 { this.db.sqlStr = "update teacher_name set teacher_password = '"+this.newpassword+"' where teacher_name = '"+this.name+"'"; } else if (this.type.equals("student")) //学生身份 { this.db.sqlStr = "update registerinfo set reg_password = '"+this.newpassword+"' where reg_name = '"+this.name+"'"; } return true; //更改成功 } else //输入密码有问题 { return false; } } public boolean execute(String session_password)throws Exception { boolean flag = false; if (this.findOlder(session_password)) //如果输入正确 { flag = true; try { this.db.sql.executeUpdate(this.db.sqlStr); //修改密码 this.db.sql.close(); //关闭数据源 } catch(SQLException e){} } return flag; }}