使用jdbc连接oracle数据库出现的问题

今天在学习使用jdbc连接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

百度了很久,都是说重启oracle服务,或者说到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)
    )
  )

可以看到其中的SERVICE_NAME = yangyihong还有PORT = 1521,那么,我上面的写法DBURL = "jdbc:oracle:thin: @localhost :1521:yangyihong"并没有问题,先记录下来,等寻找到解决方法,再进行更新!

你可能感兴趣的:(oracle,jdbc)