使用JDBC连接Oracle数据库:出现java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection 是什么意思

blackhero 2007-04-29 10:05:23
这是我连接代码;

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%--

使用myoracle数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:myoracle" ;
String DBUSER = "scott" ;
String DBPASSWORD = "tiger" ;
Connection conn = null ;
Statement stmt = null ;
%>
<%
try
{
Class.forName(DBDRIVER) ;
// 连接时必须填写用户名及密码
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
// 创建表的SQL语句
String sql = "CREATE TABLE mldntab (name varchar(20))" ;
stmt = conn.createStatement() ;
stmt.executeUpdate(sql) ;
stmt.close() ;
conn.close() ;
}
catch(Exception e)
{
out.println(e) ;
}
%>
...全文
817 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
blackhero 2007-04-29
  • 打赏
  • 举报
回复
我找到问题了

String DBURL = "jdbc:oracle:thin:@localhost:1521:myoracle" ;

这里一定要是计算机的名称:ymc

String DBURL = "jdbc:oracle:thin:@ymc:1521:myoracle" ;

这回就对了
然爷 2007-04-29
  • 打赏
  • 举报
回复
我只找到了个英文解释,我英语不好,兄弟自己看吧:
Oracle Database Connection (from oracle.com)

PROBLEM
You are attempting to connect to an Oracle instance using JDBC and you are receiving the following error.
java.sql.SQLException: Io exception:
The Network Adapter could not establish connection
SQLException: SQLState (null) vendor code (17002)

Any or all of the following conditions may also apply:

1) You are able to establish a SQL*Plus connection from the same
client to the same Oracle instance.

2) You are able to establish a JDBC OCI connection, but not a Thin
connection from the same client to the same Oracle instance.

3) The same JDBC application is able to connect from a different
client to the same Oracle instance.

4) The same behavior applies whether the initial JDBC connection
string specifies a hostname or an IP address.



REDISCOVERY
To verify whether you are hitting this problem, verify whether the Oracle instance is configured for Multithreaded Server (MTS). If the Oracle instance is not configured for MTS, you are probably encountering a different problem. Otherwise, continue. Try forcing the JDBC connection to use a dedicated server instead of a shared server. This can be accomplished in several ways. For JDBC OCI or Thin, this can be done by reconfiguring the server for dedicated connections only. This approach, however, may not be feasible in many cases. In such cases, the following options apply: For JDBC OCI:

1) Add the (SERVER=DEDICATED) property to the TNS connect string
stored in the tnsnames.ora file on the client.

2) Set the user_dedicated_server=ON in sqlnet.ora on the client.
thinker28754 2007-04-29
  • 打赏
  • 举报
回复
应该是JDBC驱动不匹配.
yzhjisji 2007-04-29
  • 打赏
  • 举报
回复
使用JDBC连接Oracle数据库:出现java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection 是什么意思


这个异常的意思是:

网络适配器不能建立连接.

楼主可以参考查找!
blackhero 2007-04-29
  • 打赏
  • 举报
回复
我用Visual Studio.Net 2005,就能连上
sqlplus也能连上

就是JDBC连Oracle连不上
blackhero 2007-04-29
  • 打赏
  • 举报
回复
Oracle 10 g release 10.2.0.1.0
thinker28754 2007-04-29
  • 打赏
  • 举报
回复
oracle用的上什么版本?

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧