operatormodel.java
来自「java课程的资料以及实验的代码」· Java 代码 · 共 73 行
JAVA
73 行
/* *OperatorModel.java:建立操作员实体类。 *包括:与数据库进行改、查操作。 */
import java.sql.*;
import java.math.*;
public class OperatorModel {
String name;
String pwd;
DbConn dbc;
Connection conn;
public OperatorModel() {
}
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 DbConn();
conn = dbc.getConnection(); int cnt=0;
String sql;
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 DbConn();
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());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?