Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


difference b/w class.forname & drivermanager.registerdriver


Hi All,  can any one tell me what is exact difference between using Class.forname() and driverManager.registerDriver().  Thanks...

Class.forName has nothing to do with JDBC. It's just a way to load a class--any class.  DriverManager.registerDriver is how you tell the JDBC DriverManager that there's a driver available to access some DB.  Of course, the above could have been gleaned by reading the docs for those classes.  Now, it so happens that properly implemented JDBC drivers will have a static initializer (which is called automatically when the class is loaded) that calls DriverManager.registerDriver to register itself--that is, calling Class.forName on a JDBC driver class should cause that class to in turn call DriverManager.registerDriver

Thank you

HI mahi, when u r using Class.forName, implicitly an instance will create and gets registered with the DriverManager class. means explicitly u  do not need to register with the driver manager,coz forName is a factory method. and  when u r using DriverManager.registerDriver, means u r getting registered to the DriverManager class.

Hi Rameshkumar.  Thank you for the contribution of a poorly worded, SMS laced and less correct version of an answer given hours earlier.  May I suggest the next time you feel like contributing that you do the following instead? Stick your head in a vat of lime Jello and shout " I  have many doubt about it!". That would be a more productive use of everyone's time.

hi nanook, i think u live in forests, better come to city , then u will know the culture here. ok

Hi Rameshkumar,  I see you didn't try my suggestion. You should. Conrtinbutions such that you have made in this thread are totally worthless. I suspect this reflects the quality of code you produce as well.   Regards,  Nanook

hello nanook i am not getting , what exactly you are saying? plz be clear , so that i can answer u correctly. ok bye

Hi Rameshkumar,  Being clear.  1) Please use real words. Plz, coz, u and ur are not real words. It really does not cost you any time to type out full words and the effect is a much clearer understanding to all of what you are saying.  2) Your contribution was useless. You responded to a thread with a poorer explanation than was given hours ago. There was no need for you to respond to this thread at all. There was especially no need for you to do so to post a poorly worded response using not real words that was also less correct than that given originally.  Contributions like you have made only serve to confuse others. They add nothing. So please use real words and if a response has already been given and is complete then please refrain from posting incoherent follow ups.  Regards,  Nanook

As we know that most of the driver has a static initializer block in which a self instance is created and registered to the DriverManager. Now if we use DriverManager.registerDriver(new foo.mydriver.Driver()) it will create 2 driver object instance. Inorder to avoid that Driver can be implemented as singletone pattern. My question is anyone have any idea why Sun doesnot mandate Driver implementation as a singleton pattern.

As we know that most of the driver has a static initializer block in which a self instance is created and registered to the DriverManager. Now if we use DriverManager.registerDriver(new foo.mydriver.Driver()) it will create 2 driver object instance.   It will only do that if that drier does in fact have a register call in its static initializer. It wouldn't necessarily have to have that, though most do. Also, it's possible that the DriverManager won't let you register two drivers of the same class. I haven't actually looked at the code though.  Inorder to avoid that Driver can be implemented as singletone pattern. My question is anyone have any idea why Sun doesnot mandate Driver implementation as a singleton pattern.  I think the docs say it's supposed to register itself. That kind of suggests that there's no reason to explicitly create and register one, and that a singleton might be a good idea. Even if the docs were more strongly worded, there's no way to enforce it anyway.

thanx for your comments, but unfortunately DriverManager doesnot take care it whether driver of same type of class is already registered or not. I have checked that with this code snippet.  Driver driver = com.mysql.jdbc.Driver(); DriverManager.registerDriver((driver);  // print drivers registered to drivermanager while (drivers.hasMoreElements()) {   System.out.println(++counter + ".>  "+ drivers.nextElement().getClass().getName()); }  // this code will show you that 2 mysql driver object is registered to drivermanager.  thanx  Suman


Related Links

J2SE J2EE
dynamic object names help
Re: UOPHX POS 406
What do u mean by random Searh??
Compilation Error
Confused about passing by reference and passing by valule
SLES-9 on AMD64 - which jdk?
Installing java SE beta 2 - Data Miner detected!
a sagestion please regarding bitmaps
Rescheduling Timers.
Problem with packages
Why do Java teachers set problems requiring an Applet solution?
Standard Options in javac, Help!
bufferedScanner = new Scanner(new BufferedReader(new FileReader(aFile)));
How do we split on the basis of a new line??
impossible show 26.3.2006 2:00