Raviraj Darade
Raviraj Darade

Reputation: 27

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

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

is throwing NullPointerException, I have tried a lot to solve it but failed.

You can check following function where the problem is occuring:

public static Connection con=null;

public static Connection getOracleConnection()
{


    try{  
        Class.forName("oracle.jdbc.driver.OracleDriver");  
        con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe",Constants.OracleUsername,Constants.OraclePassword);  
        }catch(NullPointerException npe){ npe.printStackTrace(); }
    catch(Exception e){ System.out.println("Error to create the connection "); }

    return con;
}

Upvotes: 2

Views: 3001

Answers (1)

Stephan
Stephan

Reputation: 43053

Check that the Oracle JDBC driver is in your classpath.

You can find one on the page below if not yet downloaded:

http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html

Upvotes: 1

Related Questions