我試圖運行下面的代碼被連接到遠程數據庫和檢索記錄Oracle數據庫:連接到位於遠程
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException {
// Load the Oracle JDBC driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
// 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 <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@ourcompany.com:1521:course", "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 ("name"));
System.out.println (rset.getString ("id"));
*/
rset.next();
System.out.println(rset.getString("name"));
} }
從NetBeans中運行此代碼我得到一個後錯誤:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@ourcompany.com:1521:course at java.sql.DriverManager.getConnection(DriverManager.java:604) at java.sql.DriverManager.getConnection(DriverManager.java:221) at Employee.main(Emplyoee.java:23) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)
我已經下載ojdbc14.jar的,並保存在C:\ Program Files文件\的Java \ jdk1.7.0 \ JRE \ lib文件路徑。 我不知道我哪裏去錯了... ... plz幫助我在這裏。
我試過這個...得到了同樣的錯誤。 – kpc72 2011-12-14 22:44:13
你確定jar文件在你的類路徑中嗎? – chance 2011-12-14 22:45:34