簡體   English   中英

JDBC 驅動程序不存在

[英]JDBC Driver Does Not Exist

我正在嘗試將 Java 程序連接到遠程 Oracle DB。 在網上做了一些研究后,我決定最簡單的方法是使用 Oracle JDBC 驅動程序。 我下載並運行了 jar 文件並收到消息“***** JCE UNLIMITED STRENGTH IS INSTALLED *****”。 問題是,當我嘗試將驅動程序添加到我的類路徑 (javac -classpath ojdbc8.jar Connect.java) 時,我不斷收到一條錯誤消息,指出“包 oracle.jdbc.driver 不存在”。 我一直在研究如何在線解決這個問題,但我只是感到困惑。 關於我做錯了什么的任何想法?

    import java.sql.*;

    public class Class1 {

    public static void main (String args [])
            throws SQLException
    {
        // Load the Oracle JDBC driver
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

        // 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:hr/hr@myhostname:1521:orcl",
                        "myUsername", "myPassword");

        // 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));

        conn.close(); // ** IMPORTANT : Close connections when done **
    }
}

錯誤是:

java: package oracle.jdbc.driver does not exist

您可以嘗試運行示例DataSourceSample.java嗎? 確保類路徑中有 JDBC 驅動程序。 您還可以參考此快速入門以獲取詳細說明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM