在设定了sys用户的密码为oracle之后,使用下面的代码无法取得连接。
提示ORA-01017: invalid username/password; logon denied when connecting via JDBC driver
Properties props = new Properties();
props.put("user", "sys");
props.put("password", "oracle");
props.put("internal_logon", "sysdba");
try (Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.2.7.21:1521:isdb", props)) {
System.out.println(conn);
} catch (Exception e) {
System.out.println(e);
}
grant sysdba to sys;失败,提示ORA-01994: GRANT 失败: 口令文件缺失或已禁用。
select * from v$pwfile_users; 结果为空。
/opt/oracle/product/10.2.0/db/dbs/下没有密码文件。
解决方法:
创建密码文件,如下。
su - oracle
orapwd file="/opt/oracle/product/10.2.0/db/dbs/orapwisdb" password=oracle entries=10;
"orapwisdb"里面orapw是固定前缀,isdb是数据库实例名,注意大小写。
然后重新设置sys用户的密码。
sqlplus / as sysdba
ALTER USER sys IDENTIFIED BY oracle;
commit;
quit;