(Q) How to communicate with data base?
(A) To connect to data base we have set of interfaces provided by Java.sql.*;First you need to load JDBC driver and then Make JDBC connection.
(Q) What are the different types of database drivers?
(A) Four types of drivers available
In this type, you have java API which talks to a native API (JDBC-ODBC Driver) which then talks to a database.
Type-2 (Thick/Native driver)
In this type, you have a native API which talks to a Database.
Type-3 (Network protocol driver)
It`s a three tier architecture, the clienttalks to server with network protocol diver and server uses any one from other three type of drivers. This type of driver is used when lot of concurrency can be done.
Type-4 (Pure or Thin Driver)
It`s complete Java API which talk to a Database, this is most often used driver.
(Q) How to Load the driver?
(A) Use Class.forName(), forName() is a method in Class which returns a class object, to the forName() you provide a string parameter that is the Class that you want to load. To load the Class you need to provide total path including package.
For type-1 Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
For type-2 using Oracle database Class.forName(“oracle.jdbc.driver.OracleDriver”);
(Q) How to fetch the connection?
(A) Connection is the interface in Java.sql package.
For Type-1
Connection con=DriverManager.getConnection(“jdbc:odbc:[odcb dsn]“:”username”:”password”);
(Q) What is a ResultSet ?
(A) ResultSet is a Java Object, it contains the results of executing an SQL query. In other words it is a table of data representing a database result set, which is usually generated by executing a statement that queries the database.
Sample : ResultSet rs = stmt.executeQuery(“SELECT a, b, c FROM Table1″);
(Q) What do you mean by fastest type of JDBC driver?
(A) JDBC driver performance or fastness depends on a number of issues: Quality of the driver code, size of the driver code, database server and its load, Network topology, Number of times your request is translated to a different API.