First step towards JDBC Programming

I recommend to read JDBC introduction before reading this post..

Before moving to the programming, let us first know what are the important Classes and Interfaces in JDBC API. It contains of two important packages. They are: 
  1. java.sql 
  2. javax.sql
The following figure shows the important Classes and Interfaces in these two packages.

JDBC classes and Interfaces
Fig: Important Classes and Interfaces JDBC
 Any JDBC program must perform the following five steps:
  1. Register the JDBC Driver.
  2. Establish the connection with DataBase Server.
  3. Create a Statement object to send SQL queries to DataBase Server.
  4. Send the query's to DataBase with the help of Statement object.
  5. Close the connection with DataBase Server.
         To register with JDBC Driver we use a method named "registerDriver". This method is present inside "DriverManager" Class. The following is the syntax for registering the Driver.
  • static void registerDriver(Driver);
  This method is a static method which returns no value. The parameter to be passed to this method is the object of Driver Class. But Driver is an Interface(see above figure), for which we cannot create an object. 
        In JDBC Driver software there will be classes which implements all the interfaces in JDBC API. In such classes, The class which implemented Driver interface is called as Driver Class. Hence, we are going to use the object of this class as a parameter to 'registerDriver' method.
Now let us write a small program which registers the JDBC Driver:
Registering JDBC driver
Fig: register the JDBC Driver.

No comments:

Post a Comment