资金管理系统java_Java web项目 个人资金项目管理系统管理员部分代码

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 + "");

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值