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。

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

java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list的更多相关文章

  1. java.sql.SQLException: Could not establish connection to 192.168.8.111:10000/default: java.net.ConnectException: Connection refused: connect at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveC

    java.sql.SQLException: Could not establish connection to 192.168.8.111:10000/default: java.net.Conne ...

  2. Listener refused the connection with the following error 错误解决

    原文地址 :http://blog.csdn.net/zajin/article/details/17753351 做个备份: 查询数据库当前进程的连接数: select count(*) from ...

  3. 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 .

    我安装了Oracle数据库,默认的数据库用户名是system,密码口令是安装过程中你自己设置的.可以先使用命令框,输入 sqlplus system; 然后再输入密码即可. 然后我的数据库连接工具使用 ...

  4. Hive中导入Oracle数据错误:Listener refused the connection with the following error: ORA-12505

    问题: 今天往Hive中导入Oracle数据的时候碰到了如下错误:Listener refused the connection with the following error: ORA-12505 ...

  5. 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

    一次连接数据库怎么也连接不上,查了多方面资料,终于找到答案,总结 首先应该保证数据库的服务启动 在myeclipse的数据库视图中点 右键->new 弹出database driver的窗口,  ...

  6. 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

    新装的idea开发工具后连接数据库出现如题所示错误. 1.网上搜了不少的文章,没有解决我的问题.后来细心看了一下url: 一开始url是这样子的. jdbc:oracle:thin:@:s21_pdb ...

  7. java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)(ERR=12505)(ERR

    dbc 链接orcal出错 java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=186646784)( ...

  8. java.sql.SQLException: Io 异常: Connection reset

    当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...

  9. java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed

    org.springframework.dao.TransientDataAccessResourceException: ### Error updating database. Cause: ja ...

随机推荐

  1. linux 启动tomcat

    操作步骤: 第一步:进入tomcat的bin目录 cd /usr/local/tomcat/bin 第二步:使用tomcat关闭命令 ./shutdown.sh 第三步:查看tomcat是否关闭 ps ...

  2. 第二章 Vue快速入门--8 v-bind指令的学习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  3. 《Python基础教程》第五章:条件、循环和其他语句

    在Python中赋值运算和比较运算是可以连接的,运算符可以连在一起使用,如:0<age<100 ==运算符判定两个对象是否相等,is判定两者是否等同(同一个对象) 断言,在错误条件出现时直 ...

  4. 一次使用自定义 Http Header 引发的血案

    一次使用自定义 Http Header 引发的血案 HttpClient Http Header 自定义 nginx 不转发  起因 最近在整理我们产品的 OpenAPI Demo (Python.C ...

  5. vue组件开发练习--焦点图切换

    1.前言 vue用了有一段时间了,开发的后台管理系统也趋于完善,现在时间比较算是有点空闲吧!这个空闲时间我在研究vue的另外的一些玩法,比如组件,插件等.今天,我就分享一个组件的练手项目--焦点图切换 ...

  6. static和assets的区别

    assets和static两个都是用于存放静态资源文件. 放在static中的文件不会进行构建编译处理,也就不会压缩体积,在打包时效率会更高,但体积更大在服务器中就会占据更大的空间 放在assets中 ...

  7. php类知识---魔术方法__toString,__call,__debugInfo

    <?php class mycoach{ public function __construct($name,$age) { $this->name = $name; $this-> ...

  8. Java-收邮件

    import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail. ...

  9. lombok使用及常用注解

    简介 大部分项目中都必不可少的包含数据库实体(Entity).数据载体(dto,dataObject),而这两部分都包含着大量的没有业务逻辑的setter.getter.空参构造,同时我们一般要复写类 ...

  10. 【原】关于executeQuery与ResultSet

    今天老实犯糊涂,再总结一下以前的知识吧~ executeQuery()永远不会返回null 这一点很重要,也很容易让人忽视.举个例子吧; 比如,在数据库中,只有两个用户user1,user2的密码是& ...