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查看:

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

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

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

你可能感兴趣的:(oracle用户无密码jdbc)