him jain wrote:I wrote the code for JDBC : "Class.forName("com.mysql.jdbc.Driver");"
then obviously, it'll try to connect to mysql.
No. That statement loads a class, but it doesn't cause anything else to happen. The driver to be used is selected by examining the DB URL, not by checking which drivers are loaded.
MaheshS Kumbhar wrote:But I read somewhere on documentation available on sun site that, drivers that are registered first with DriverManager class are always loaded first and chosen for connecting to the database. Second statement that I read was drivers listed in jdbc.drivers system property are always registered first. So these two statements together tempting me that drivers listed in jdbc.drivers system property will always be on priority to be chosen for connection to the database irrespective of explicitly loading of drivers using Class.forName.
As I mentioned above, the driver to be used is chosen according to the connection URL; it doesn't matter when or how it was loaded. Obviously, it must be loaded
somehow before the connection is made. You can even have different drivers loaded for the same DB server, but since those will have different URLs it's clear which one the code intends to use.
If the question is about what happens if you have multiple version of the same driver (which would thus be registered for the same DB URL), then I'd strongly advise not to do that - it's a bug waiting to happen.