开发者社区> 问答> 正文

使用java连接oracle数据库?报错

直接上代码:

<%!
 public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
 public static final String DBURL = "jdbc:oracle:thin: @localhost :1521:yangyihong" ;
 public static final String DBUSER = "scott" ;
 public static final String DBPASSWORD = "tiger" ;
%>
<%
 Connection conn = null ;
 PreparedStatement pstmt = null ;
 ResultSet rs = null ;
%>
<%
 Class.forName(DBDRIVER) ;
 conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
 String sql = "SELECT empno,ename,job,hiredate,sal,comm FROM emp ORDER BY empno" ;
 pstmt = conn.prepareStatement(sql) ;
 rs = pstmt.executeQuery() ;
%>

而此时,会报错,提示如下

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12518, TNS:listener could not hand off client connection
The Connection descriptor used by the client was:
localhost:1521:yangyihong

小弟已经进入到D:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora目录下,确认了我的文件内容为

# tnsnames.ora Network Configuration File: D:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

YANGYIHO =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = LBDZ-03081718)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = yangyihong)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

按照上面内容,localhost:1521:yangyihong这个写法应该没错啊。另外,各种服务也都已经启动了,通过sqlplusw可以正常启动数据库。求大神解救。

展开
收起
爱吃鱼的程序员 2020-06-22 15:40:58 614 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    Oracle中的<spanstyle="font-family:'WenQuanYiMicroHeiMono','WenQuanYiMicroHei','MicrosoftYaheiMono','MicrosoftYahei',sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">tnsnames.ora文件内<spanstyle="font-family:'WenQuanYiMicroHeiMono','WenQuanYiMicroHei','MicrosoftYaheiMono','MicrosoftYahei',sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">YANGYIHO和你的java的连接的URL中的<spanstyle="font-family:'WenQuanYiMicroHeiMono','WenQuanYiMicroHei','MicrosoftYaheiMono','MicrosoftYahei',sans-serif;font-size:14px;line-height:22px;background-color:#FFFFFF;">yangyihong对不上。谢了!果真是这原因!

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">jdbc:oracle:thin: <atarget="_blank"rel="nofollow">@<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">YANGYIHO

    <spanstyle="font-size:14px;line-height:22px;">或者<atarget="_blank"rel="nofollow">

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">jdbc:oracle:thin: <atarget="_blank"rel="nofollow">@<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">LBDZ-03081718<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">:1521:<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">yangyihong

    2020-06-22 15:41:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
DTCC 2022大会集锦《云原生一站式数据库技术与实践》 立即下载
阿里云瑶池数据库精要2022版 立即下载
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载

相关镜像