Connecting with Oracle in Java application
•
Java
I have downloaded Oracle express 11g and installed it Now I want to connect it from a Java application This 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 try to connect it, it will show me the 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)
However, when I tried to connect to the "Xe" database, it was already connected
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","password123");
I don't know why? Please give me some references or tips
Solution
I think you have a misunderstanding between database schema and database type In Oracle, Xe represents Express Edition of Oracle database Orcl means Oracle
In MySQL
DriverManager.getConnection("jdbc:MysqL://localhost:3306/test","password123"); `test` is a database schema.
In Oracle Xe
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","password123"); DriverManager.getConnection("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl","password123"); `example`: database schema name and DB user name are the same.
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码