简体   繁体   中英

Oracle Express 18c log on from Java jdbc application

new Oracle Express user here,

I did the db install w/o problems in my Win 64 environment, used sqlplus from terminal to create user and grant him roles and privileges, and finally this user works fine with the local db from Oracle SQLcl utility - tables, queries etc.

The problem comes when I try to use the provided boilerplate code from Oracle for Java. In Eclipse, in new project, with added jdbc8 jars the tested in SQLcl user creadentials are rejected with exception: java.sql.SQLException: ORA-01045: user C##DBUSER lacks CREATE SESSION privilege; logon denied.

Here is the Oracle boiler code used, with my local details :

  OracleDataSource ods = new OracleDataSource();
  ods.setURL("jdbc:oracle:thin:@//localhost:1521/XEPDB1"); 
  ods.setUser("c##dbUser"); 
  ods.setPassword("dbUserPassowrd"); 
  Connection conn = ods.getConnection();

  PreparedStatement stmt = conn.prepareStatement("SELECT 'Hello World!' FROM dual");
  ResultSet rslt = stmt.executeQuery();
  while (rslt.next()) {
    System.out.println(rslt.getString(1));
  }

Would appreciate your help, thanks!

正确的连接字符串必须是:“jdbc:oracle:thin:@//localhost:1521/XE”,以说明创建用户并授予权限的数据库名称。

As Oracle says:

user C##DBUSER lacks CREATE SESSION privilege; logon denied.

Connect to the Oracle database as a privileged user (such as SYS) and

grant create session to c##dbuser;

(or whichever user name it really is).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM