尝试连接到Oracle java.lang.ClassNotFoundException时出错:oracle.jdbc.driver.OracleDriver

时间:2013-06-11 09:08:08

标签: oracle

我正在尝试通过以下程序连接到Oracle数据库。但是会抛出一个错误 java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver“

我的计算机上只安装了SQL开发人员客户端,而实际数据库存储在服务器上。请帮助解决问题

package test;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

public class DBConnection {

    public static void main(String[] argv) {

        System.out.println("-------- Oracle JDBC Connection Testing ------");

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            System.out.println("Where is your Oracle JDBC Driver?");
            e.printStackTrace();
            return;

        }

        System.out.println("Oracle JDBC Driver Registered!");

        Connection connection = null;


    enter code here
        try {

            connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@hostname:5800:SID", "user","password");

        } catch (SQLException e) {

            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return;

        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }

}

1 个答案:

答案 0 :(得分:1)

将Oracle JDBC Driver jar添加到类路径

可以从here

下载Oracle数据库版本的驱动程序