Topic: java+oracle(No suitable driver)

  Print this page

1.java+oracle(No suitable driver) Copy to clipboard
Posted by: cooper131
Posted on: 2006-11-15 20:57


import java.sql.*;

public class testDB{
public static void main(String[] args){
String serverName="127.0.0.1";
try{
Class c=oracle.jdbc.driver.OracleDriver.class;
String url="jdbc:oracle: @"+serverName+":1521: XE";
Connection conn=DriverManager.getConnection(url,"12345","12345");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from user_db");
while(rs.next()){
System.out.print("id:"+rs.getString(1));
System.out.println("name:"+rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
}catch(SQLException sqle){
System.out.println("database is error.~~~~~~~~~~~~!!!!");
sqle.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}

}
}

=======================================
在DOS在运行:
database is error.~~~~~~~~~~~~!!!!
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at testDB.main(testDB.java:9)
=======================================
当我用eclipse运行时,通过了,读到数据了。
注:在DOS下我用的是与eclipse一样的ojdbc14.jar文件。
我还试过Classes12.jar,也不行。
让我最想不通的是同一段代码一个通过,另一个不行!!!
我认为是运行环境有所不同,但就是找不到有什么不同。
高手指点一下,谢谢

2.Re:java+oracle(No suitable driver) [Re: cooper131] Copy to clipboard
Posted by: why
Posted on: 2006-11-16 07:45

String url=jdbc:oracle:thin:@"+serverName+":1521:XE";

3.Re:java+oracle(No suitable driver) [Re: cooper131] Copy to clipboard
Posted by: cooper131
Posted on: 2006-11-16 11:10

先谢谢你,能抽时间回答这个问题

呵呵,那个空格是我后加的,不加出个小鬼脸,还有那个thin,我也加过不行。

我用这个(带thin的)url在eclipse运行通过了,在DOS下不行,不知为什么?

4.Re:java+oracle(No suitable driver) [Re: cooper131] Copy to clipboard
Posted by: cooper131
Posted on: 2006-11-21 20:31

已解决,我jdk用1.5,后来我改用1.4.2后好用了

5.Re:java+oracle(No suitable driver) [Re: cooper131] Copy to clipboard
Posted by: 九佰
Posted on: 2006-11-24 16:57

cooper131 wrote:
先谢谢你,能抽时间回答这个问题

呵呵,那个空格是我后加的,不加出个小鬼脸,还有那个thin,我也加过不行。

我用这个(带thin的)url在eclipse运行通过了,在DOS下不行,不知为什么?


在发贴的确定按纽上有一选项: 禁止在这个帖子中使用笑脸标记
把它选上就不会出现笑脸了.

6.Re:java+oracle(No suitable driver) [Re: cooper131] Copy to clipboard
Posted by: yuandian1984
Posted on: 2008-03-06 09:04



   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923