当尝试连接Oracle时出现错误java.lang.ClassNotFoundException: Oracle .jd



我正在尝试通过以下程序连接到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!");
        }
    }
}

将您的Oracle JDBC Driver jar添加到类路径

可以从这里下载Oracle数据库版本的驱动程序

相关内容

最新更新