The following line of code Class.forName("MyDriver"); will load the Driver with name MyDriver and also registers it with DriverManager by calling DriverManager.registerDriver().There is no need for you to register that driver explicitly by calling DriverManager.registerDriver() because Class.forName is doing both the things for you.
Originally posted by Sujith Kanaparthi: Hi kooskuntla venkat,
The following line of code Class.forName("MyDriver"); will load the Driver with name MyDriver and also registers it with DriverManager by calling DriverManager.registerDriver().There is no need for you to register that driver explicitly by calling DriverManager.registerDriver() because Class.forName is doing both the things for you.
If you use DriverManager explicitly, you will register the Driver twice and there will be two instances held by the DriverManager. Ithe grand scheme of tings the memory is negligable (unless you keep registering it over and over and over again) so you should avid doing it, but otherwise don't worry about it.
Ithe grand scheme of tings the memory is negligable (unless you keep registering it over and over and over again)
Hi David,
I hope Every Driver class has a static block of that creates a new Instance of the Diver and registers it with DriverManager.Since it is a static block that is being executed, even if try to register it once again the code is not going to execute once again. David please comment on this . Regards Sujith
You can call Class.forName(...) as many times as you like and the Class will only be loaded once, and as a side effect the Class will only register itself with the DriverManager once.
BUT (and this was true the last time I checked the DriverManager source, but feel free to see if they have fixed it) calling DriverManager.registerDriver(...) will cause the Driver to be registered every time the line is called.
So the following code:
will register the Driver twice the first time it is called, and once each time it is called after that. I'm pretty sure this is not what you intend.