java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
2015-04-08 16:42
781 查看
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。
如果这里是正确的,那么就可能是监听程序的错误。这种错误可以自行搜索一下,网上的关于题目上的错误讨论的最多的就是这种原因。可以自行搜索解决方案来解决。
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。
如果这里是正确的,那么就可能是监听程序的错误。这种错误可以自行搜索一下,网上的关于题目上的错误讨论的最多的就是这种原因。可以自行搜索解决方案来解决。
相关文章推荐
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:lis
- java.sql.SQLException: Listener refused the connection with the following error:ORA-12505
- 数据库报ORA-12519;java.sql.SQLException: Listener refused the connection with the following error解决办法
- Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
- 状态: 失败 -测试失败: Listener refused the connection with the following error: ORA-12505, TNS:listener does
- Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
- java.sql.SQLException: Listener refused the connection with the following error:
- Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently
- 状态: 失败 -测试失败: Listener refused the connection with the following error: ORA-12505, TNS:listener does
- java.sql.SQLException: Listener refused the connection with the following error
- 今天写一个JSP+Oracle的项目,遇到了 Listener refused the connection with the following error:ORA-12519:
- ORA-12514错误:Listener refused the connection with the following&
- Listener refused the connection with the following error 错误解决
- Listener refused the connection with the following error 错误解决
- 连接Oracle数据库时遇到:Listener refused the connection with the following error。。。。
- Listener refused the connection with the following error 错误解决
- Listener refused the connection with the following error 错误解
- listener refused the connection with the ORA-12505错误解决方案--Oracle侦听服务解决终级办法
- Listener refused the connection with the following error 错误解决
- Listener refused the connection with the following error 错误解决(最大连接数)