java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list


package DisplayAuthors;
import  java.sql.*;
public class DisplayAuthors 
{
private static final  String  DATABASE_URL="jdbc:oracle:thin:@localhost:1521:orcl";                             //here  is  5  rows
public static void main(String[] args) {
Connection  connection=null;
Statement  statement=null;
ResultSet  resultset=null;
try
{
connection=DriverManager.getConnection(DATABASE_URL,"scott","123456");
statement=connection.createStatement();
resultset=statement.executeQuery("select  *  from  emp");
ResultSetMetaData  metadata=resultset.getMetaData();
int  numberofcolumns=metadata.getColumnCount();
for(int  count=1;count<numberofcolumns;count++)
{
System.out.printf("%-8s\t",metadata.getColumnName(count));
}
System.out.println();
while(resultset.next())
{
for(int count=1;count<numberofcolumns;count++)
{
System.out.printf("%-8s\t", resultset.getObject(count));
}
System.out.println();
}
}
catch(SQLException  sqlexception)
{
sqlexception.printStackTrace();
}
finally
{
try
{
resultset.close();
statement.close();
connection.close();
}
catch(Exception  exception)
{
exception.printStackTrace();
}
}


}


}

代码如上,出现这个错误的原因有很多,如果是代码上的原因,就应该检查一下第五行代码那里"dbc:oracle:thin:@localhost:1521:orcl"中的"orcl"是不是创建数据库时的那个SID,如果不是就会出错。注意此处不是连接名,而是SID。

如果这里是正确的,那么就可能是监听程序的错误。这种错误可以自行搜索一下,网上的关于题目上的错误讨论的最多的就是这种原因。可以自行搜索解决方案来解决。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 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 使用Oracle SQL Developer连接数据库中遇到Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently know of SID given in connect descriptor Connection to Oracle failed. [66000][12505] Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor . 66000][12505] Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor oracle.n et.ns.NetException: Listener refuse Oracle SQL developer连接数据库报错:ORA-12505 listener refused the connection with the following error…… Oracle中Error while performing database login with the XXXdriver; Listener refused the connection with the following error; ORA-12505,TNS:listener does not currently know of SID given inconnect descrip java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver 与 java.sql.SQLException: Listener refused the connection with the following error: 及”java连接oracle数据库“ java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERR Oracle连接出现error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 
粤ICP备18138465号  © 2018-2026 CODEPRJ.COM