使用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:oracleproduct10.2.0db_1NETWORKADMINtnsnames.ora目录下,确认了我的文件内容为
# tnsnames.ora Network Configuration File: D:oracleproduct10.2.0db_1networkadmintnsnames.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可以正常启动数据库。求大神解救。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢了!果真是这原因!
Oracle中的
tnsnames.ora文件内YANGYIHO和你的java的连接的URL中的yangyihong对不上。