由于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

之后运行就没有问题了

http://blog.csdn.net/u013479571/article/details/48004509

原文地址:https://www.cnblogs.com/angelye/p/7597150.html