📄 operatordao.java
字号:
package dao.operator;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;
import common.dbconnection.DbConnection;
import vo.Operator;
//import common.JdbcDemo;
//import common.DbConnection;
public class OperatorDao {
private Connection con = null;
private Statement sta = null;
private ResultSet res = null;
private Vector v = null;
public boolean insertOperatorInfo(Operator value) {
boolean flag = false;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "insert into ktv_operator_info(OPERATOR_ID,OPERATOR_NAME,OPERATOR_LEVEL,PASSWORD)"
+ " values('"
+ value.getOperatorId()
+ "','"
+ value.getOperatorName()
+ "','"
+ value.getOperatorLevel()
+ "','123')";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
if (set.next()) {
flag = true;
}
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return flag;
}
public boolean deleteOperatorInfo(String operatorId) {
boolean flag = false;
Connection con = null;
PreparedStatement stmt = null;
ResultSet set = null;
String sql = "delete from ktv_operator_info where operator_Id ='"
+ operatorId.trim() + "'";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.prepareStatement(sql);
stmt.executeUpdate();
flag = true;
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return flag;
}
public boolean updateOperatorInfo(Operator value) {
boolean flag = false;
Connection con = null;
PreparedStatement stmt = null;
ResultSet set = null;
try {
con = new DbConnection().getConnection();
String sql = "update ktv_operator_info set OPERATOR_NAME='"
+ value.getOperatorName() + "' ,operator_level= '"
+ value.getOperatorLevel() + "'where OPERATOR_ID='"
+ value.getOperatorId() + "'";
System.out.println(sql);
stmt = con.prepareStatement(sql);
set = stmt.executeQuery(sql);
flag = true;
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return flag;
}
public Vector getOperatorInfo() {
Vector v = null;
Connection con = null;
Statement stmt = null;
ResultSet set = null;
String sql = "select * from KTV_operator_INFO";
System.out.println(sql);
try {
con = new DbConnection().getConnection();
stmt = con.createStatement();
set = stmt.executeQuery(sql);
v = new Vector();
while (set.next()) {
int OPERATOR_ID = Integer.parseInt(set.getString(1));
String OPERATOR_NAME = set.getString(2);
String OPERATOR_LEVEL = set.getString(3);
String PASSWORD = set.getString(4);
v.addElement(new Operator(OPERATOR_ID, OPERATOR_NAME,
OPERATOR_LEVEL, PASSWORD));
}
} catch (Exception e) {
System.out.println("异常信息: " + e.getMessage());
}
return v;
}
// 取得所有管理人员预定信息
public Vector getAllOperator() {
v = null;
con = null;
sta = null;
res = null;
Operator op = null;
try {
v = new Vector();
String selectSql = "select * from ktv_operator_info";
//con = new JdbcDemo().getConnection();
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(selectSql);
int count = 0;
// String temp = null;
while (res.next()) {
op = new Operator();
op.setOperatorId(res.getInt("OPERATOR_ID"));
op.setOperatorName(res.getString("OPERATOR_NAME"));
op.setPassword(res.getString("PASSWORD"));
op.setOperatorLevel(res.getString("OPERATOR_LEVEL"));
// System.out.println(op);
v.addElement(op);
count++;
}
if (count == 0) {
throw new Exception("数据库中不存在这种条件的记录,请你重新输入查询条件");
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return v;
}
//删除管理人员信息
public boolean deleteOperator(int demo) {
boolean flag = false;
String sql = "delete from ktv_operator_info where OPERATOR_ID = "
+ demo;
try {
//con = new JdbcDemo().getConnection();
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(sql);
flag = true;
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
//更新管理人员信息
public boolean updateOperator(int demo, String demo2) {
boolean flag = false;
try {
//con = new JdbcDemo().getConnection();
con = new DbConnection().getConnection();
con.setAutoCommit(false);
sta = con.createStatement();
String sqlupdate = "update ktv_operator_info set PASSWORD = '"+demo2+"' "+"where OPERATOR_ID = "
+ demo;
sta.executeQuery(sqlupdate);
flag = true;
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
//新建管理人员信息
public boolean insertOperator(Operator demo) {
boolean flag = false;
String sql = "insert into ktv_operator_info(OPERATOR_ID, OPERATOR_NAME, OPERATOR_LEVEL, PASSWORD) "
+ "values("
+ demo.getOperatorId()
+ ",'"
+ demo.getOperatorName()
+ "','"
+ demo.getOperatorLevel()
+ "','"
+ demo.getPassword()
+ "')";
try {
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(sql);
flag = true;
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
public boolean isExistOperator(int user){
boolean flag = false;
String sql = "select * from ktv_operator_info where OPERATOR_ID = "+ user;
try {
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(sql);
while (res.next()) {
flag = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
public boolean getAOperator(int user,String password){
boolean flag = false;
String sql = "select * from ktv_operator_info where OPERATOR_ID =" + user + " and PASSWORD = '"+password+"'";
try {
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(sql);
while (res.next()) {
flag = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
public boolean getAOperator(int user,String password,String level){
boolean flag = false;
String sql = "select * from ktv_operator_info where OPERATOR_ID =" + user + " and PASSWORD = '"+password+"' and Operator_level = '"+level+"'";
try {
con = new DbConnection().getConnection();
sta = con.createStatement();
res = sta.executeQuery(sql);
while (res.next()) {
flag = true;
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
con.close();
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -