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.
But I have a little concern as we all must know that whatever classed we are using are mostly in rt.jar (in /jre/lib Package). and others are in (/jre/lib/ext) but I searched a lot about these driver classes e.g. oracle.jdbc.driver.OracleDriver. now could anyone suggest me that where are these classes situated.
Is there any difference either we use Class.forName() or we can use import statment for loading of these classes.
Why we always use Class.forName() method to load the Driver Classes, I have never seen any Program using Import statement for driver classes. Is that so, that we cann't import these classes as we are doing for other one e.g.(java.util.*),
I have also read the API Specification of Class.forName() method it's simple stating that it is used to Load a class dynamically. But Why we need to do so, because JAVA itself use Dynamic Class loading process.
You can put your driver classes/jar files anywhere you wnt, as long as they are in the classpath of your application. If you put them into jre/lib/ext, then the JVM will find them automatically, and they don't need to be added to the classpath.
It's possible to import the driver classes like other Java classes. But it's often necessary that the same program uses different databases (and sometimes different drivers), so by keeping the class name and URL out of the code, you make it much easier to hook up the application to a different database. It's not about dynamically loading the class, but about dynamically determining which class to load, and then loading it.
I am also agreed with your statement that initially JDK comes with basic Interfaces then if we need some specific driver then we have to download it from www. but my concern is that in my m/c when I am pretty much confident that I haven't downloaded any specific driver.
According to My Understanding I am using driver for MS-Access, I think that JDBC driver used with MS-Access is automatically installed in M/C with MS-Access Installation.
Now what might be the possible locations of these driver classes. That's what I really want to know.??
Well I am pretty about your questions that's for sure.
Here is what you might be asking I don't know.
1) JDBC is an API. It's a collection of interfaces with no implementations. Implementations are provided by drivers.
2) Access drivers are ODBC and provided by Microsoft (with the OS I think I always have Office and Access installed on all my machines so I really off the top of my head could not tell you what install installs them but the basic ODBC drivers come from Microsoft anyway)
3) The JdbcOdbcBridge driver is provided by Sun as part of the JRE as a matter of convienence for you.
4) Never import driver packages or classes directly! That's a bad idea all around. (The only exception to this rule is if you are trying to use implementation specific features like Oracle blobby bits)
5) Nobody ever said the String you pass to Class.forName has to be hard coded. You could read the String at runtime from a Properties file or ask the user or any number of alternates.
Actually I just want to see the Implementation of these classes.
How they are designed .. And One more thing is I want to have a look on design patter of these drivers.
Maximilian Xavier Stocker
Joined: Sep 20, 2005
Originally posted by Ankur Sharma: Actually I just want to see the Implementation of these classes. How they are designed .. And One more thing is I want to have a look on design patter of these drivers.
Why are you sticking your tongue out and rolling your eyes like this? I am finding it a bit offensive to be honest as I am taking the time to answer your questions and while you said in your last post that you knew everything I said you clearly didn't in the earlier posts in this thread. Anyway please stop with the eyerolling and the tongue sticking out.
Now the answer to your question is.
No. You can't see this. The bridge driver is almost all native code anyway so it's not even Java, plus while Sun gives it away Sun did not develop the bridge driver so it's doubtful how much source you will find anyway.
If you would like to see examples of how JDBC drivers are implemented then you can look at any one of the many free open source drivers that are out there. I would recommend looking at the MySQL JConnector driver source mainly because I know it to be relatively simple.
As far as looking for design patterns in the drivers. Don't. There isn't very much to see. These are drivers implementing a known specification so the concept of design patterns in this context is very limited in scope.