概述
package Thejava;
import java.sql.ResultSet;
public class Admin extends Conn{
// 定义成员变量
private int adminID;
private String adminName;
private String adminPassword;
// 执行各种操作的SQL语句
private String strSql;
public Admin() throws ClassNotFoundException {
adminID = 0;
adminName = "";
adminPassword = "";
strSql = "";
}
/**
* @添加用户记录
*/
//insert into admin(name,password)values(adminName,adminPassword)
public boolean addAdmin() {
strSql = "insert into admin";
strSql = strSql + "(";
strSql = strSql + "name,";
strSql = strSql + "password";
strSql = strSql + ")";
strSql = strSql + " values(";
strSql = strSql + "'" + adminName + "',";
strSql = strSql + "'" + adminPassword + "'";
strSql = strSql + ")";
boolean isAdd = super.AlterSql(strSql);
return isAdd;
}
/**
* @判断用户名是否存在 by adminName
*/
public boolean isExist() {
strSql = "select * from admin where name='"+adminName+"'";
ResultSet rs = null;
boolean isExist = false;
try {
rs = super.QuerySql(strSql);
while(rs.next()) {
isExist = true;
}
} catch (Exception e) {
System.out.println(e.toString());
}
return isExist;
}
/**
* @判断用户名和密码是否正确
*/
public boolean adminValid() {
strSql = "select * from Admins where name='" + adminName + "' and password='" + adminPassword + "'";
ResultSet rs = null;
boolean isValid = false;
try {
rs = super.QuerySql(strSql);
while (rs.next()) {
this.adminID = rs.getInt("id");
isValid = true;
}
} catch (Exception e) {
System.out.println(e.toString());
}
return isValid;
}
/**
* @获取某个用户的信息 by id
*/
public boolean init() {
strSql = "select * from admin where id=";
strSql = strSql + adminID;
try {
ResultSet rs = super.QuerySql(strSql);
if (rs.next()) {
this.adminID = rs.getInt("id");
this.adminName = rs.getString("name");
this.adminPassword = rs.getString("password");
return true;
} else {
return false;
}
} catch (Exception e) {
System.out.println(e.toString());
return false;
}
}
/**
* @return the adminID
*/
public int getAdminID() {
return adminID;
}
/**
* @param adminID the adminID to set
*/
public void setAdminID(int adminID) {
this.adminID = adminID;
}
/**
* @return the adminName
*/
public String getAdminName() {
return adminName;
}
/**
* @param adminName the adminName to set
*/
public void setAdminName(String adminName) {
this.adminName = adminName;
}
/**
* @return the adminPassword
*/
public String getAdminPassword() {
return adminPassword;
}
/**
* @param adminPassword the adminPassword to set
*/
public void setAdminPassword(String adminPassword) {
this.adminPassword = adminPassword;
}
public static void main(String[] args) throws ClassNotFoundException {
Admin admin = new Admin();
admin.setAdminName("admin");
admin.setAdminPassword("admin");
boolean res = admin.adminValid();
System.out.println(res + "");
}
}
最后
以上就是淡然小蜜蜂为你收集整理的Java web项目 个人资金项目管理系统管理员部分代码的全部内容,希望文章能够帮你解决Java web项目 个人资金项目管理系统管理员部分代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复