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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package UnitTest;
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;
public class TestPgRole {
/**
* 功能:删除用户
*
* @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();
}
public static void main(String[] args) {
//初始化
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 + "已成功删除!");
}
createUser(user_name, pwd);
System.out.println("用户名" + user_name + "已创建,密码为:" + pwd);
//PG数据库权限概念 角色,用户,权限
}
}