【发布时间】:2010-11-06 10:45:43
【问题描述】:
我是 Java 相关 Web 开发的新手,我似乎无法获得一个使用 JDBC 工作的简单程序。我正在使用现成的 Oracle 10g XE 和 Eclipse EE IDE。从到目前为止我检查过的书籍和网页中,我已将问题缩小到错误写入的数据库 URL 或丢失的 JAR 文件。我收到以下错误:
java.sql.SQLException: 找不到适合 jdbc:oracle://127.0.0.1:8080 的驱动程序
使用以下代码:
import java.sql.*;
public class DatabaseTestOne {
public static void main(String[] args) {
String url = "jdbc:oracle://127.0.0.1:8080";
String username = "HR";
String password = "samplepass";
String sql = "SELECT EMPLOYEE_ID FROM EMPLOYEES WHERE LAST_NAME='King'";
Connection connection;
try {
connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement();
System.out.println(statement.execute(sql));
connection.close();
} catch (SQLException e) {
System.err.println(e);
}
}
}
无论如何,数据库 URL 的正确格式是什么?他们被提及很多,但我找不到描述。
编辑(分辨率):
根据 duffymo 的回答,我从 Oracle's download site 获得了 ojdbc14.jar,并将其放入 Eclipse 项目的引用库中。然后我把代码的开头改成
...
// jdbc:oracle:thin:@<hostname>:<port>:<sid>
String url = "jdbc:oracle:thin:@GalacticAC:1521:xe";
...
它成功了。
【问题讨论】: