由于SID连接不匹配,监听器拒绝连接。
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
package com.test.practice; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class TestConnectionDatabase { public static void main(String[] args) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url="jdbc:oracle:thin:@:1521:xe"; String username="scott"; String password="root"; Connection conn = DriverManager.getConnection(url, username, password); System.out.println("连接成功"); String msg=conn.getMetaData().getDatabaseProductName(); System.out.println(msg); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
在注册表中查看自己的sid
第十二行 最后根据自己的SID 我的应该写为orcl
之后运行就没有问题了
请留下你的足迹...