Connection with oracle in java application(在 Java 应用程序中与 oracle 连接)
问题描述
我已经下载并安装了 oracle express 11g 版本.现在我想从 java 应用程序连接它.这是我的连接代码:-
I have downloaded oracle express 11g edition and installed that.Now i want to connect it from java application. Here is my Connection code :-
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:example", "example","password123");
但是当我尝试连接它时,它显示我出现以下异常.
But when i am trying to connect it, it showing me following exception.
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at javaapplication3.JavaApplication3.main(JavaApplication3.java:40)
但是当我尝试连接xe"数据库时,它已连接.
But when i am trying to connect with "xe" database then it is connected.
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "example","password123");
我不知道为什么会这样?请给我一些参考或提示.
I dont know why this is happening?. Please give me some reference or hint.
推荐答案
我想,你对 database schema
和数据库类型有误解.在Oracle
中,XE
表示oracle数据库的Express Edition
.ORCL
表示 Oracle 公司
.
I think, you are misunderstanding between database schema
and database type. In Oracle
, XE
means Express Edition
of oracle database. ORCL
means Oracle Corp
.
在mysql中
DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "example","password123");
`test` is a database schema.
在 Oracle XE 中
In Oracle XE
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "example","password123");
DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl","example", "password123");
`example`: database schema name and DB user name are the same.
这篇关于在 Java 应用程序中与 oracle 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Java 应用程序中与 oracle 连接
基础教程推荐
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01