Few question or confusions about JDBC. 1) The argument we pass to class.forname(".... ") is for loading jdbc driver,in some books its written database vendors give free jdbc drivers,but in bruce eckel's thinking in java its written this jdbc driver e.g(sun.jdbc.odbc.jdbcodbcdriver) comes with jdk toolkit,so please clear from where do we load this driver either from database sofware or from jdk. 2) Second question is about some lines from java tutorial by sun in which it is written "after loading class.forname("......"), the second step in establishing a connection is to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea: Connection con = DriverManager.getConnection (url,"myLogin","myPassword"); This step is also simple, with the hardest thing being what to supply for url . If you are using the JDBC-ODBC Bridge driver,the JDBC URL will start with jdbc dbc: . The rest of the URL is generally your data source name or database system. If one of the drivers you loaded recognizes the JDBC URL supplied to the method DriverManager.getConnection , that driver will establish a connection to the DBMS specified in the JDBC URL. My questions are :
* What is this jdbc url? * If we have already loaded the driver through class.forname then why it is written as first line of tutorial "The second step in establishing a connection is to have the appropriate driver connect to the DBMS.
the JDK comes with a driver for connecting to a database through the ODBC bridge on the Operating System. You can also use drivers that will connect to a database without using the JDBC-ODBC bridge. Usually these drivers are faster because the ODBC is reletively slow. Loading the Driver and then establishing a connection to the databse is two different things. When you create a connection, the url is the location of the database. For instance, I am connection to a MySQL database using a type IV 100% pure java Driver like this: con = DriverManager.getConnection("jdbc:mysql://ip goes here ort/"); If you download a Driver and do not use the JDBC-ODBC Driver that comes with the JDK, the Driver will have documentation on what you need to supply for the URL. Remember, loading the instance of the Driver and establishing a connection are two totally different things. Loading the instance of the Driver only creates the Driver object used to interact with the database. The Connectin class is used to connect to the database via the Driver. Hope that helps a little.
Joined: May 10, 2001
from where do we load this driver either from database sofware or from jdk. The jdbcodbc bridge that comes from sun will work for any data source that you can connect to through odbc - it is, however, a type 1 driver which can be slower than others because of the extra layers involved. Many database manufacturers will freely create a type 4 driver (all java and connects directly to the datasource) to speed your connection. 2) * What is this jdbc url? Check this out for a good explaination of the url. * If we have already loaded the driver through class.forname then why it is written as first line of tutorial "The second step in establishing a connection is to have the appropriate driver connect to the DBMS. The first step is to actually load the driver with Class.forName(). The second step is to actually make the connection. hope that helps
Joined: Nov 22, 2000
thanks a lot for detailed replies,most of confusion is clear but still one left :-) suppose i'm using oracle driver as example in my book like class.forname(oracle.jdbc.driver.OracleDriver) and in url we're using (jdbc racle:thin bname.... ) As Gregg said "Loading the instance of the Driver only creates the Driver object used to interact with the database.The Connectin class is used to connect to the database via the Driver" i got it no confusion,but i just want to clear * what is the relationship between driver and jdbc url in locating a database,or i must say how driver is using that url in locating a database? I hope I'm clear this time.