为什么jdbc连接oracle不成功(请看程序和编译。。)??

kingdom1 2001-09-26 11:10:48
// Application1.java *****程序*****

import java.sql.*;
import oracle.jdbc.*;

public class Application1
{
public static void main (String args []) throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");

String URL="jdbc:oracle:thin:@130.130.0.228:1521:ora";
try {
Connection conn = DriverManager.getConnection (URL,"scott","tiger");
conn.setAutoCommit(true);
// Create a Statement
Statement stmt = conn.createStatement ();

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

// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
} catch(SQLException ex) {
System.err.println("-----SQLException-----");
System.err.println("SQLState: " + ex.getSQLState());
System.err.println("Message: " + ex.getMessage());
System.err.println("Vendor: " + ex.getErrorCode());
ex.printStackTrace();
}
}
}

//***** 编译执行结果 ****
D:\JBuilder4\jdk1.3\bin\javaw -classpath "E:\kong\test1\classes;D:\JBuilder4\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilder4\jdk1.3\jre\lib\i18n.jar;D:\JBuilder4\jdk1.3\jre\lib\jaws.jar;D:\JBuilder4\jdk1.3\jre\lib\rt.jar;D:\JBuilder4\jdk1.3\jre\lib\sunrsasign.jar;D:\JBuilder4\jdk1.3\lib\dt.jar;D:\JBuilder4\jdk1.3\lib\tools.jar;F:\orant\jdbc\lib\classes102.zip;F:\orant\jdbc\lib\classes111.zip" test1.Application1
-----SQLException-----

SQLState: null

Message: Refused:ROR=(CODE=12505)(EMFI=4))))

(请各位指教,谢谢)
...全文
164 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
leizhengdeng 2001-09-27
  • 打赏
  • 举报
回复
用户名和密码不对吧
wallety 2001-09-27
  • 打赏
  • 举报
回复
请参看这段代码
/**
* Connect to Oracle DB over thin driver
*/
static public void connect_to_oracle_thin( String host, String port,
String sid, String login,
String pwd )
throws DBError
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@@(description=(address_list=" +
"(address=(protocol=tcp)(host="+host+")"+
"(port="+port+"))) (connect_data=(sid="+sid+")))";
DBConnection = DriverManager.getConnection(url, login, pwd);
}
catch (ClassNotFoundException class_ex)
{
class_ex.printStackTrace();
throw new DBError();
}
catch (java.sql.SQLException sql_ex)
{
sql_ex.printStackTrace();
throw new DBError();
}
name_=sid; login_=login; pwd_=pwd;
}
Yang_Sun 2001-09-27
  • 打赏
  • 举报
回复
没遇到,其实JDBC不难的
yjtian 2001-09-26
  • 打赏
  • 举报
回复
From the output you pasted, we can see the string "Refuesd".
Maybe you need another userid/password other than "scott/tiger".

You can do a small test like this:

in Oracle/Net8 Configuration/Net Service
add a new net service point to 130.130.0.228:1521:ora

then use sql plus to connect to this service, using
the same user/password as in your program (scott/tiger).

see what happens.
Yang_Sun 2001-09-26
  • 打赏
  • 举报
回复
呵呵,想帮你,苦于懒得装oracle服务器了,这样吧,你把这个程序改改,然后把结果贴出来,大家帮你找原因

import java.sql.*;
import oracle.jdbc.*;

public class Application1
{
public static void main (String args []) throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");

String URL="jdbc:oracle:thin:@130.130.0.228:1521:ora";
try {
Connection conn = DriverManager.getConnection (URL,"scott","tiger");
conn.setAutoCommit(true);
if (conn = null) {
System.out.println("Can't get connection");
}
} catch (Exception e) {
e.printStackTrace();
}

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

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

// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
} catch(SQLException ex) {
System.err.println("-----SQLException-----");
System.err.println("SQLState: " + ex.getSQLState());
System.err.println("Message: " + ex.getMessage());
System.err.println("Vendor: " + ex.getErrorCode());
ex.printStackTrace();
}
}
}

呵呵,我怀疑你连Connection也没得到,你运行一下这个把,呵呵,我顺手加了几句,不知对否,你再稍微改改,大家好继续帮你分析
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
(刚才未copy完全)
//***** 编译执行结果 ****

D:\JBuilder4\jdk1.3\bin\javaw -classpath "E:\kong\test1\classes;D:\JBuilder4\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;D:\JBuilder4\jdk1.3\jre\lib\i18n.jar;D:\JBuilder4\jdk1.3\jre\lib\jaws.jar;D:\JBuilder4\jdk1.3\jre\lib\rt.jar;D:\JBuilder4\jdk1.3\jre\lib\sunrsasign.jar;D:\JBuilder4\jdk1.3\lib\dt.jar;D:\JBuilder4\jdk1.3\lib\tools.jar;F:\orant\jdbc\lib\classes102.zip;F:\orant\jdbc\lib\classes111.zip" test1.Application1
-----SQLException-----

SQLState: null

Message: Refused:ROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:228)

at oracle.jdbc.driver.OracleConnection.<init> (OracleConnection.java:110)

at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:148)

at java.sql.DriverManager.getConnection(DriverManager.java:517)

at java.sql.DriverManager.getConnection(DriverManager.java:177)

at test1.Application1.main(Application1.java:15)
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
请帮我一下?
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
是设置jdbc的原因吗?
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
在 Connection conn = DriverManager.getConnection (URL,"scott","tiger");
执行中抛出异常,连接不成功。
在SQL*PLUS中是可以连接的。
如果用JDBC-ODBC连接,比较容易。为什么JDBC这么难,大家有无遇到同样情况。
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
在 Connection conn = DriverManager.getConnection (URL,"scott","tiger");
执行中抛出异常,连接不成功。
在SQL*PLUS中是可以连接的。
如果用JDBC-ODBC连接,比较容易。为什么JDBC这么难,大家有无遇到同样情况。
kingdom1 2001-09-26
  • 打赏
  • 举报
回复
多谢大家的帮助。

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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