package dao.product.mysql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import dao.product.DbUtil;
import dao.product.TOperatorDAO;
import bean.TOperator;
public class MySQLTOperatorDAO implements TOperatorDAO {
/*
* this method verify whether the login is successfull
* return
* common.Constant.ERROR
* common.Constant.ADMIN
* common.Constant.OPERATOR
*/
public int verifyOperator(String operator_id, String operator_pwd) {
int result = common.Constant.ERROR;
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "select * from TOPERATOR where operator_id=? and operator_pwd=?";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, operator_id);
prepStmt.setString(2, operator_pwd);
ResultSet rs = prepStmt.executeQuery();
while(rs.next()) {
String role = rs.getString("is_admin");
if("Y".equalsIgnoreCase(role)) {
result = common.Constant.ADMIN;
}
if("N".equalsIgnoreCase(role)) {
result = common.Constant.OPERATOR;
}
}
return result;
} catch (SQLException e) {
e.printStackTrace();
return common.Constant.ERROR;
} finally {
db.close();
}
}
public boolean add(TOperator operator) {
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "INSERT INTO TOPERATOR VALUES(?,?,?,?)";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, operator.getOperator_id());
prepStmt.setString(2, operator.getOperator_name());
prepStmt.setString(3, operator.getOperator_pwd());
prepStmt.setString(4, operator.getIs_admin());
prepStmt.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
db.close();
}
}
public boolean delete(String id) {
id = fillVacancy(id);
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "delete TOperator where operator_id=?";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, id);
prepStmt.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
db.close();
}
}
public boolean update(TOperator operator) {
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "update TOperator set operator_name=?,operator_pwd=?,is_admin=? where operator_id=?";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, operator.getOperator_name());
prepStmt.setString(2, operator.getOperator_pwd());
prepStmt.setString(3, operator.getIs_admin());
prepStmt.setString(4, operator.getOperator_id());
prepStmt.execute();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
db.close();
}
}
public TOperator findByID(String id) {
id = fillVacancy(id);
TOperator operator = new TOperator();
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "select operator_id,operator_name,operator_pwd,is_admin from TOperator where operator_id=?";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
prepStmt.setString(1, id);
ResultSet rs = prepStmt.executeQuery();
while(rs.next()) {
operator.setOperator_id(rs.getString("operator_id"));
operator.setOperator_name(rs.getString("operator_name"));
operator.setOperator_pwd(rs.getString("operator_pwd"));
operator.setIs_admin(rs.getString("is_admin"));
}
return operator;
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
db.close();
}
}
public List findAll() {
List<TOperator> list = new ArrayList<TOperator>();
DbUtil db = new MySQLDbUtil();
Connection conn = db.getConnection();
String sql = "select operator_id,operator_name,operator_pwd,is_admin from TOperator";
try {
PreparedStatement prepStmt = conn.prepareStatement(sql);
ResultSet rs = prepStmt.executeQuery();
while(rs.next()) {
TOperator operator = new TOperator();
operator.setOperator_id(rs.getString("operator_id"));
operator.setOperator_name(rs.getString("operator_name"));
operator.setOperator_pwd(rs.getString("operator_pwd"));
operator.setIs_admin(rs.getString("is_admin"));
list.add(operator);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
db.close();
}
}
public static String fillVacancy(String str) {
if(str.length()==10) {
return str;
}
if(str.length() > 10) {
return null;
}
StringBuffer sb = new StringBuffer(str);
for(int i = 0; i< 10-str.length(); i++) {
sb.append(" ");
}
return sb.toString();
}
public static void main(String[] args) {
// TOperatorDAO test = new OracleTOperatorDAO();
// TOperator operator = new TOperator();
// operator.setOperator_id("seeafafa");
// operator.setOperator_name("Shit2");
// operator.setOperator_pwd("123");
// test.add(operator);
// operator = test.findByID("a87gha ");
// System.out.println(operator.getOperator_name());
//
// //test.delete("f33333 ");
// List list = test.findAll();
// System.out.println(((TOperator)list.get(0)).getOperator_name());
// List list = new ArrayList();
// list = test.findAll();
// System.out.println(((TOperator)list.get(2)).getOperator_pwd());
// System.out.println(((TOperator)list.get(2)).getOperator_name());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
ChinaMobile.rar_chinamobile_中国移动
共191个文件
java:62个
class:62个
gif:39个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 32 浏览量
2022-09-23
07:38:21
上传
评论
收藏 1.87MB RAR 举报
温馨提示
这是我在东方标准学习的时候做的一个项目,是中国移动的一个子管理任务模块,采用MVC模式设计,调试成功。
资源推荐
资源详情
资源评论
收起资源包目录
ChinaMobile.rar_chinamobile_中国移动 (191个子文件)
OracleTOperatorDAO.class 5KB
MySQLTOperatorDAO.class 5KB
OracleTCustomerDAO.class 5KB
MySQLTCustomerDAO.class 5KB
OracleTAccountDAO.class 4KB
MySQLTAccountDAO.class 4KB
OracleTUserDAO.class 4KB
MySQLTUserDAO.class 4KB
OracleTChargeDAO.class 4KB
MySQLTChargeDAO.class 4KB
OracleTChargeRuleDAO.class 4KB
MySQLTChargeRuleDAO.class 4KB
OracleTMobileDAO.class 4KB
MySQLTMobileDAO.class 4KB
CustomerService.class 3KB
ActionController.class 3KB
AccountService.class 3KB
TChargeService.class 3KB
TOperatorService.class 3KB
OracleDbUtil.class 2KB
MySQLDbUtil.class 2KB
MobileService.class 2KB
UserService.class 2KB
NewAccountAction.class 2KB
TCustomer.class 2KB
SetCharacterEncodingFilter.class 2KB
TMobileService.class 2KB
OpenAccountAction.class 2KB
TChargeRuleService.class 2KB
NewUserAction.class 2KB
RoleVerifier.class 2KB
TUser.class 2KB
NewCustomerAction.class 1KB
OracleDAOFactory.class 1KB
ModifyOperatorAction.class 1KB
ChargeConfig_1Action.class 1KB
MySQLDAOFactory.class 1KB
AddOperatorAction.class 1KB
ChargeConfig_2Action.class 1KB
LoginAction.class 1KB
ResourceConfigAction.class 1KB
GetAllOperatorAction.class 1KB
LogoutAction.class 1KB
GetOperatorAction.class 1KB
Constant.class 1KB
TOperator.class 1KB
TAccount.class 1KB
TMobile.class 1KB
DAOFactory.class 1009B
TCharge.class 935B
TChargeRule.class 927B
Tool.class 863B
DbUtil.class 506B
TCustomerDAO.class 404B
TOperatorDAO.class 375B
TChargeRuleDAO.class 374B
TChargeDAO.class 365B
DBType.class 319B
TMobileDAO.class 300B
Action.class 289B
TAccountDAO.class 270B
TUserDAO.class 258B
.classpath 412B
style.css 3KB
index_04.gif 53KB
index_04.gif 53KB
index_01.gif 35KB
index_01.gif 35KB
index_06.gif 16KB
index_06.gif 16KB
index_02.gif 8KB
index_02.gif 8KB
logo.gif 8KB
logo.gif 8KB
pic04.gif 7KB
pic04.gif 7KB
pic05.gif 7KB
pic05.gif 7KB
pic03.gif 6KB
pic03.gif 6KB
pic01.gif 6KB
pic01.gif 6KB
pic02.gif 6KB
pic02.gif 6KB
index_03.gif 5KB
index_03.gif 5KB
index_05.gif 3KB
index_05.gif 3KB
close.gif 108B
Arrow1.gif 104B
Arrow1.gif 104B
right1.gif 73B
left2.gif 73B
right2.gif 73B
left1.gif 73B
drop1.gif 58B
drop2.gif 58B
blank.gif 43B
spacer.gif 43B
blank(1).gif 43B
共 191 条
- 1
- 2
资源评论
我虽横行却不霸道
- 粉丝: 72
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功