📄 operatormodel.java
字号:
/**
*OperatorModel.java:建立操作员实体类。
*包括:与数据库进行改、查操作。
*/
package zichan;
import java.sql.*;
import java.math.*;
public class OperatorModel {
String name;
String pwd;
DBConnt dbc;
Connection conn;
public OperatorModel() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public OperatorModel(String n,String e) {
name = n;
pwd = e;
}
public void setAll(String e,String p) {
name = e;
pwd = p;
}
public String getName() {
return name;
}
private String getPwd() {
return pwd;
}
public int verify() {
dbc = new DBConnt();
conn = dbc.getConnection();
int cnt=0;
String sql;
String sql = "SELECT count(*) FROM operator where name = '"+this.name+"' and pwd = '"+this.pwd+"'";
try {
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery (sql);
while (rset.next()) {
cnt = rset.getInt(1);
}
conn.commit();
rset.close();
stmt.close();
conn.close();
}
catch (java.sql.SQLException s) {
System.out.println("exception: " + s.getMessage());
}
return cnt;
}
public void update() {
dbc = new DBConnt();
conn = dbc.getConnection();
try {
PreparedStatement pstmt =
conn.prepareStatement("update OPERATOR set PWD = ? where name = ?");
pstmt.setString(1, pwd);
pstmt.setString(2, name);
pstmt.execute();
conn.commit();
conn.close();
}
catch (java.sql.SQLException s) {
System.out.println("exception: " + s.getMessage());
}
}
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -