describe.java
来自「用于餐饮类的源代码!只能在java下使用!!!」· Java 代码 · 共 156 行
JAVA
156 行
package cmis.common;
import cmis.database.DBPoolManager;
import java.sql.*;
public class Describe {
public Describe() {
}
public String getNameDescription(int type, int code) {
String res = "";
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select description from code_info where type = "
+ type + " and code = " + code;
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
res = rest.getString(1);
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("Get Description info SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return res;
}
public String getTypeDescription(int type) {
String res = "";
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select name from code_info where type = " + type;
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
res = rest.getString(1);
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("Get Type Description info SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return res;
}
public String getDepartment(int dept) {
String res = "";
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select OrganName from organ where OrganID = " + dept;
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
res = rest.getString(1);
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("Get Department info SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return res;
}
public int getUserDepartment(String user) {
int dept = 0;
if (user == null) {
return 0;
}
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select a.OrganID from organ a, Staff b where "
+ "b.OrganID = a.OrganID and b.UserCode = '" + user + "'";
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
dept = rest.getInt(1);
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("Get User Department info SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return dept;
}
public String getUserName(String userId) {
String res = userId;
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select UserName from Staff where UserCode = '"
+ userId + "'";
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
res = rest.getString(1);
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("Get User Name SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return res;
}
public boolean isAdmin(String userId) {
boolean reflag = false;
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select UserName from Staff a, Staff_role b where a.UserId=b.UserId and a.UserCode = '"
+ userId + "' and b.RoleId= 0 ";
Statement selectStatement = dbpool.conn.createStatement();
ResultSet rest = selectStatement.executeQuery(sql);
if (rest.next()) {
reflag = true ;
}
rest.close();
selectStatement.close();
} catch (SQLException ex) {
System.err.println("IsAdmin SQLException : "
+ ex.getMessage());
} finally {
dbpool.freeConnection();
}
return reflag;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?