I have this method to connecting to oracle 11g xe. It´s still returning exception java.lang.NullPointerException. I use Eclipse IDE. Please help, i don´t know how to fix it.
public static Connection connectDB() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
Connection connection = null;
try {
// Load the JDBC driver
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName).newInstance();
// Create a connection to the database
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "xe";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "peter";
String password = "pass";
connection = DriverManager.getConnection(url, username, password);
System.out.println(connection);
} catch (ClassNotFoundException e) {
// Could not find the database driver
} catch (SQLException e) {
// Could not connect to the database
}
System.out.println(connection);
return connection;
}