I have installed Oracle Database 21c Express. I want to connect to it using JDBC. However I'm getting following error:
No suitable driver found for jdbc:oracle:thin:@localhost:1521:XE
I am using JDK 17 and ojdbc11.jar. Is this correct ojdbc version for JDK17?
I have set CLASSPATH in Environment Variables ⟶ System variables in CLASSPATH variable.
Following is the code that I am trying:
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "test");
System.out.println("connection Establisted");
System.out.println(connection);
connection.close();
connection = null;
}
Following is the error that I am getting:
I have read that the following line is not required, is that true?
Class.forName("oracle.jdbc.driver.OracleDriver");
Also as I have added the ojdbc jar file in the CLASSPATH, I have not added it anywhere in the project files. Is that correct?