opengauss遇到的问题

1.The account has been locked.报错

gsql -d postgres -p 26000 -r //以root进入数据库

alter user njp account unlock;//进数据库内部修改使其解锁

2.忘记密码

gsql -d postgres -p 26000 -r //以root进入数据库

alter user njp password "改后密码";

3.启动数据库

su - omm

gs_om -t start

 4.jdbc连接数据库遇到的问题

import java.sql.*;
public class openGaussDemo {

    static final String JDBC_DRIVER = "org.postgresql.Driver";
    static final String DB_URL = "jdbc:postgresql://211.282.200.03:26000/test2?ApplicationName=app1";//26000是端口号,后面跟的test2是数据库名称,211.282.200.03是服务器地址
// 数据库的用户名与密码,需要根据自己的设置
static final String USER = "dpoper";//dboper是用户名
    static final String PASS = "dba@1234";//dba是密码
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        try{
            // 注册 JDBC 驱动
            Class.forName(JDBC_DRIVER);

            // 打开链接
            System.out.println("连接数据库...");
            conn = DriverManager.getConnection(DB_URL,USER,PASS);

            // 执行查询
            System.out.println(" 实例化Statement对象...");
            stmt = conn.createStatement();
            String sql;
            sql = "SELECT * FROM public.student";//sql语句,public是所在模式名,student是表名字。
            ResultSet rs = stmt.executeQuery(sql);

            // 展开结果集数据库
            while(rs.next()){
                // 通过字段检索
                String sno = rs.getString("sno");
                String sname = rs.getString("sname");

                // 输出数据
                System.out.print("sno: " + sno);
                System.out.print(", sname: " + sname);
                System.out.print("\n");
            }
            // 完成后关闭
            rs.close();
            stmt.close();
            conn.close();
        }catch(SQLException se){
            // 处理 JDBC 错误
            se.printStackTrace();
        }catch(Exception e){
            // 处理 Class.forName 错误
            e.printStackTrace();
        }finally{
            // 关闭资源
            try{
                if(stmt!=null) stmt.close();
            }catch(SQLException se2){
            }// 什么都不做
            try{
                if(conn!=null) conn.close();
            }catch(SQLException se){
                se.printStackTrace();
            }
        }
        System.out.println("Goodbye!");
    }
}

 

posted @ 2021-05-19 21:50  北冥有扶摇  阅读(1980)  评论(0编辑  收藏  举报