Cannot find Oracle jdbc driver

I am new to connecting Java and the database, and I am trying to make a very simple connection to the oracle database. When I run this code:

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");
    }

I get a conclusion Can't find database driver. I use Eclipse Helios, and I added the ojdbc6.jarbuild path to my path (the first thing I double checked), and I use JDK 1.6.

+3
source share
1 answer

Make sure .jar is also on the execution path. In eclipse, go to Run -> Run Configurations -> Select the configuration tab -> classpath. Your bank should be in the "user records", if you do not select "Add Bank" on the right side.

+8
source

All Articles