Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.
1- DB URL ? why do we have a URL to connect to a DB ? Is there any other way for a Java program (besides URL) to connect to a DB ?
2- What is the meaning of "registered drivers" ? How does one register a driver ?
Bear Bibeault wrote:A forum isn't a good replacement for a tutorial. You should find a JDBC tutorial and that will answer these and many other questions.
I try to look at the tutorials and google too before I seek help here. Sometimes the tutorials
do not explain everything. Half-understanding is good as not understanding.
I hope that you can still help me.
justin smythhe wrote:The points 1 and 2 in my post. You are answering my questions with questions;
Exactly. I'm trying to get you to ShowSomeEffort and hone your questions down into answerable ones.
What do I do now ?
Have you read through a JDBC tutorial? If so, which one?
To spot answer your questions:
1) The JDBC URL identifies the database to be connected to.
2) The driver manager does exactly what it says: manages the loaded JDBC drivers.
For more details, a book or a tutorial would be appropriate. Forums do not exist so that people can avoid reading on their own. It's here to answer specific questions that you might have after reading books and tutorials, or to help with specific code problems.
No one has time to enter in long passages that repeat what's already available elsewhere.
lol...Bear, I saw your picture in this forum before. Really Justin picked the best one. I can't stop laughing....oh God. You guys are great !!!
By the way, Justin it is good that you started reading those most boring API's but as Jayesh said, look for sample codes and try to run those by your own (use IBM-RAD or Eclipse) and see which part you can't understand. I am also learning Java everyday and this forum is an awesome place for me to motivate myself because here everyone will help you to overcome that point where you will get stuck. So no worries ok.
About JDBC, (in sort) try to see the whole picture. Suppose you wrote an Application. And your application needs to access data from a Database (called Data source). Now what you will do? First you have to locate where is your targated database-right? It can be in your local machine or in any remote server. So you need that address and any how you have to tell your app to read or write from that database. Here that URL comes, you see. It is nothing but the address where your database is located.
Ok....so you have your app and the database address. What will be the next step? Your application should understand how to reach to that database. Well, again at this point, did you realize that your App is doing so many stuff? You are writing logic in your App, writing SQL queries in your App so that it can read/write data from database..bla...bla...and finally you have the database address where you want to connect.
Now ask yourself.....out there you will find so many different types of Databases such as MySQL, DB2, JBOSS. Each database has their own dealing style with user's request. Now who will take care of this whole uncertainty? How you application will know how to talk to different types of Databases out there? How they will know what you want? You know what....there the JDBC API comes! It is saying...wait Justin.....I am here.....in your App you do your part. Just give me proper access information to your target database address. And once I will be connected with that database then you don't have to worry. I will do my part and will give you the resultset which your App is looking for. Nice ha !! And the heart of JDBC API is the "DriverManager" who is actually doing all those stuff for you. As you want to use that Manager to make your life simple, therefore you need to add that "DriverManager" (means register that Manager) in your code.
The best way to learn about these stupid boring APIs is that (at least to me), once you will understand what for you will be using those APIs at there basic level, then always look at your problem statement and ask.."Oh....I know that JDBC API does help to connect with Database. Now I need to trace the connection log in my console. Is there any way this API can help?" ....owala....this API has a method called "getLogStream" to do that task. So use that happily.
See...life is simple and beautiful ha. Good Luck Justin
Learning the JAva API word for word is not a good way to learn java. The Java API is a reference, not a guide. Learning Java by reading the Java API is a lot like appreciating the Mona Lisa by looking at it through a microscope. Definetly can be interesting, but the beauty comes in when you look at it as a whole. SImilarly, the way you learn Java is by learning how to use it, not by rote learning of each API ever written.
Joined: Jul 06, 2012
Faisal Fuad wrote:
....this API has a method called "getLogStream" to do that task. So use that happily.
Hey ! I really appreciate all the help that you gave me. I am going to try "getLogStream". But it is deprecated.
Do you know what can be used instead of "getLogStream" ?
Jayesh A Lalwani wrote:Learning the JAva API word for word is not a good way to learn java. The Java API is a reference, not a guide. Learning Java by reading the Java API is a lot like appreciating the Mona Lisa by looking at it through a microscope. Definetly can be interesting, but the beauty comes in when you look at it as a whole. SImilarly, the way you learn Java is by learning how to use it, not by rote learning of each API ever written.
I did not mean rote. I mean, i have to understand every word and sentence they use in the api tutorials.
I want to know the reasons and logic behind the words in those tutorials.
It's still pointless to go over the API word for word without understanding how to use the API first. If you don't understand how to make a database call using Java, the javadocs in java.sql are going to make zero sense to you. The same goes for every API in Java. There's a reason most books start by teaching you fundamentals concepts and code examples first, and then go into the API last. Hint: because it works.
The APIs are meant for to be a reference for someone who already knows how to program using that API.