You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8 KiB

1 year ago
package UnitTest;
1 year ago
import com.YunXiao.Util.SyncUtil;
import com.dsideal.QingLong.Util.CommonUtil;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.util.List;
1 year ago
public class TestPgRole {
1 year ago
/**
*
*
* @param user_name
*/
public static void delUser(String user_name) {
String sql = "DROP USER ?";
Db.update(sql, user_name);
}
/**
*
*
* @param user_name
* @param pwd
*/
public static void createUser(String user_name, String pwd) {
String sql = "CREATE USER ? WITH PASSWORD ?";
Db.update(sql, user_name, pwd);
}
/**
*
*
* @param user_name
* @return
*/
public static boolean isExistUser(String user_name) {
String sql = "SELECT * FROM pg_user WHERE usename = ?";
List<Record> list = Db.find(sql, user_name);
return !list.isEmpty();
}
1 year ago
public static void main(String[] args) {
1 year ago
//初始化
SyncUtil.init();
//综合素质评价系统 数据库访问用户名zhszpj,密码:随机生成, 表名前缀(建议,非强制要求)zhszpj
String user_name = "zhszpj";
String pwd = CommonUtil.getSixRandom();
if (isExistUser(user_name)) {
System.out.println("用户名" + user_name + "已存在,将删除!");
delUser(user_name);
System.out.println("用户名" + user_name + "已成功删除!");
1 year ago
}
1 year ago
createUser(user_name, pwd);
System.out.println("用户名" + user_name + "已创建,密码为:" + pwd);
//PG数据库权限概念 角色,用户,权限
1 year ago
}
1 year ago
}