博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JDBC连接ORACLE无法登陆java.sql.SQLException: ORA-01017: invalid username/password; logon denied...
阅读量:4567 次
发布时间:2019-06-08

本文共 1778 字,大约阅读时间需要 5 分钟。

当用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;).   
  • Check your tnsnames.ora to ensurethat the TNS service name points to the correct server and instance name. If you specify an incorrect tnsnames.ora service 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查看:

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

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

转载于:https://www.cnblogs.com/biaoJM/p/10186703.html

你可能感兴趣的文章
【2019.8.14 慈溪模拟赛 T1】我不是!我没有!别瞎说啊!(notme)(BFS+DP)
查看>>
多任务--进程 及 进程间通信
查看>>
多线程/多进程+QProgressBar实现进度条
查看>>
多任务(进程)案例----- 拷贝文件夹
查看>>
Kotlin的快速入门
查看>>
底层原理
查看>>
21. Merge Two Sorted Lists
查看>>
shiro设置加密算法源码解析
查看>>
实验四
查看>>
win8.1镜像制作
查看>>
Windows 服务开发框架介绍 - Topshelf
查看>>
php,字符串(二)
查看>>
Sizzle前奏
查看>>
Paint Chain HDU - 3980(sg)
查看>>
Chales常用操作
查看>>
C++ 运算符重载<<
查看>>
windows镜像
查看>>
Flask 模板语法
查看>>
ZOJ FatMouse' Trade 贪心
查看>>
音乐播放器
查看>>