This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Dear all, I read in books that Class.forName("driverClass") loads the jdbc driver in java virtual machene and Driver.getConnection("url") establishes connection to the database.
My question is if I have two jdbc programs to interact with the same database why do I need to Class.forName("driverClass") in both the programs. Instead I could use Class.forName("driverClass") in first program and Driver.getConnection("url") in both the programs because the driver class is already loaded in the JVM through the first program.
The Class.forName() registers the driver in the current JVM process and it stays registered in that process until it terminates.
It does not register the driver globally on the computer for all processes to see. The registration does not have any effect outside that single process.
You mention that you have two programs. I assume that means each program is running in it's own JVM process. The two processes are independent of each other. What is registered in one process is not visible in the other. Each program will need to register the driver within it's instance of the JVM.