免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1588 | 回复: 1
打印 上一主题 下一主题

java oracle 连接错误 谢谢解答!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-11 19:31 |只看该作者 |倒序浏览
一下为员代码,编译通过:
import java.sql.*;

class test
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
/* try{
Class.forName("oracle.jdbc.driver.OracleDriver";
}catch(Exception e){
System.out.println("No Driver!";
}
*/
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
String url = "jdbcracle:thin202.197.237.90:1521:mydomain";
String userName = "scott";
String password = "tiger";

if (args.length > 0) url = args[0];
if (args.length > 1) userName = args[1];
if (args.length > 2) password = args[2];
System.out.println(url);
System.out.println(userName);
System.out.println(password);
Connection conn =
DriverManager.getConnection (url, userName, password);

// Create a Statement
Statement stmt = conn.createStatement ();

// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from Test";

// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}

错误提示:
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter c ould not establish the connection
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java :125)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java :162)
        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java :274)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:322)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java: 347)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:150)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio n.java:32)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:549)
        at java.sql.DriverManager.getConnection(DriverManager.java:525)
        at java.sql.DriverManager.getConnection(DriverManager.java:171)
        at test.main(test.java:31)
给点建议呀!!

论坛徽章:
0
2 [报告]
发表于 2006-09-11 20:41 |只看该作者
我已经找到原因了,没有打开监听进程!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP