How to load a JDBC driver? Ans:Load and Register the - TopicsExpress



          

How to load a JDBC driver? Ans:Load and Register the Driver: In general Driver is an interface provided by Sun Microsystems and whose implementation classes are provided by the Database Vendors as part of their Database Softwares. To load and Register the Driver first we have to make available Driver implementation to JDBC application.For this we have to set classpath environment variable to the location Where we have Driver implementation class. If we want to use Type1 Driver provided by Sun MicroSystems in our JDBC applications then it is not required to set classpath environment variable because Type1 Driver was provided by Sun MicroSystems as part of Java Software in the form of sun.jdbc.odbc.JdbcOdbcdriver If we want to use Type1 Driver in our JDBC applications then before loading we have to Configure the Microsoft product odbc Driver. To configure Microsoft product odbc Driver we have to use the following path. To setting DSN:- Start | Control Panel | System and Security | Administrative Tools | Data Sources (ODBC) | user DSN | Click on Add button | Select Microsoft ODBC for the Oracle | Click on Finish button | Provide DSN name (provide any name) | Click on OK -->To load and register Driver in our Jdbc applications we have to use the following method from class ‘Class’ Public static Class forName(String class_Name) Eg:Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); When JVM encounter the above instruction JVM will pickup the parameter that is JDBCOdbcDriver Class name and JVM will search for its .class file in the current location,if it is not available then JVM will search for it in Java predefined library. If JVM identify JDBCODBCDriver.class file in Java pre-defined library(rt.jar) then JVM will load JdbcOdbcDriver class byte code to the memory. At the time of loading JdbcOdbcDriver class byte code to the memory JVM will execute a static block, As part of this JVM wiil execute a method call like DriverManager.registerDriver(--); by the execution of registerDriver() method only JDBCOdbcDrvier will be available to our Jdbc applications. In case of Type1 Driver if we use either Jdbc 4.0 version or Jdk 6.0 version then it is optional To perform loading and register the driver step because JVM will perform Drvier registration automatically at the time of establishing the connection between Java application and Database. NOTE:To prepare Jdbc applications Java API has provided the required pre-defined library in the form of java.sql package so that we have to import this package in our Java file. Import java.sql.*; java.sql package includes the following pre-defined library to design Jdbc applications. java.sql package includes the following predefined library:- I-----interface C-------class 1. Driver (I) 2. DriverManager (C) 3. Connection (I) 4. Statement (I) 5. PreparedStatement (I) 6. ResultSet (I) 7. ResultSetMetaData (I) 8. DatabaseMetaData (I) 9. Savepoint(i)
Posted on: Tue, 02 Dec 2014 05:22:28 +0000

Trending Topics



Recently Viewed Topics




© 2015