What will the command
Class.forName("oracle.jdbc.driver.OracleDriver")
exactly do while connecting to a Oracle database? Is there an alternate way of doing the same thing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It obtains a reference to the class object with the FQCN (fully qualified class name)
oracle.jdbc.driver.OracleDriver.It doesn’t "do" anything in terms of connecting to a database, aside from ensure that the specified class is loaded by the current classloader. There is no fundamental difference between writing
Class.forName("com.example.some.jdbc.driver")calls show up in legacy code that uses JDBC because that is the legacy way of loading a JDBC driver.From The Java Tutorial:
Further reading (read: questions this is a dup of)