oracle用户无密码jdbc,JDBC连接ORACLE无法登陆java.sql.SQLException: ORA-01017: invalid username/password; logon d...

当用jdbc连接Oracle数据库的时候

private Connection getConnection() throws SQLException

{

OracleDataSource ods = new OracleDataSource();

ods.setUser("biaoJM");

ods.setPassword("123456");

ods.setURL("jdbc:oracle:thin:@localhost:1521:orcl");

return ods.getConnection();

}

出现:

java.sql.SQLException:ORA-01017: invalid username/password; logon denied

但是我在sqlplus中可以登录

可能的原因如下:

Checklistfor ORA-01017 errors:select username from dba_users;

The core issue with anORA-01017 error is an invalid user ID and passwords combination, but other thanan incorrect password, there are user ID issues that may contribute to theORA-01017 error:

It may be that the userID is invalid for the target system - The user ID exists as theusername columnin the dba_users view.

Check your $ORACLE_SIDenvironmental parameter.  If your $ORACLE_SID is set to the wrong systemID then you may get a ORA-01017 error because you are connecting to the wrongdatabase.

If using (ops$ or) you need to verify that the user ID is valid.  You can tellif you are using external authentication because you connect without providinga user/password combination, and only provide a forward slash to the connectstring, (e.g. connect / as sysdba;).

Checkyourtnsnames.orato ensurethat the TNS service name points to the correct server and instance name. If you specify an incorrect tnsnames.oraservice name, thenthe user ID and password may not exist in that database.

我的原因是第二条

在sqlplus用conn as sysdba登陆

用select name from V$database;查看当前的SID,发现是FIRSTDB

那么我的URL应该将orcl改为FIRSTDB

之后就可以了

我的Oracle一共有两个数据库,分别为orcl和firstdb,这个可以执行Oracle中的administration assistance for Windows查看:

ca561639a9b631efaf8b90c5e3d1dc99.png

注:Oracle安装目录下有JDBC的文件夹,里面有一份文档很有参考价值,说明了如何配置以及如何使用

D:\app\Administrator\product\11.2.0\dbhome_1\jdbc

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值