找不到Oracle jdbc驱动程序
我是java和数据库连接的新手,我试图与oracle数据库建立非常简单的连接。当我运行此代码时:
import java.sql.*;import oracle.jdbc.pool.OracleDataSource;
public class Hello 
{
public String sayHtmlHello() 
{
    try {
        // Load the JDBC driver
        String driverName = "oracle.jdbc.driver.OracleDriver";
        Class.forName(driverName);
        // Create a connection to the database
        String serverName = "sever2";
        String portNumber = "1521";
        String sid = "serv1";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid;
        String username = "user";
        String password = "pass";
        OracleDataSource ods = new OracleDataSource();
        ods.setUser(username);
        ods.setPassword(password);
        ods.setURL(url);
        Connection conn = ods.getConnection();
        System.out.println("Connection made?");
    } catch (ClassNotFoundException e) {
        // Could not find the database driver
        System.out.println("Can't find database driver");
    } catch (SQLException e) {
        // Could not connect to the database
        System.out.println("Can't connect to database");
    }
我得到了输出Can't find database driver。我正在使用Eclipse
Helios,并且已将其添加ojdbc6.jar到构建路径中(我仔细检查了第一件事),并且正在使用JDK 1.6。
回答:
检查.jar是否也在您的运行路径上。在eclipse中,转到运行->运行配置->选择配置->类路径选项卡。如果您的jar不在右侧选择“添加jar”,则需要在“用户条目”中。
以上是 找不到Oracle jdbc驱动程序 的全部内容, 来源链接: utcz.com/qa/405878.html








