JDBC Tutorial Introduction


Before going into the definition, let us see some scenario. Suppose you go to a Bank ATM center (I call it as a ATM client) to know your account balance. You insert the card, type the pin number, click a button, you will get a small print out. You are happy; but let us see the operations that take place at the backend. When you insert, the account number goes to the Bank Server when you click the balance button. Then how the Bank server returns the balance to you? Is there any programmer sitting at the server side, to take your account number, open the database, read the balance and send back to you. If it is the case, how many programmers are required on the server side to answer the lakhs requests coming from ATMs, branch offices and online banking operations. May be a few thousands. Is it really happens like this?

No, not at all. Everything should go programmatically. There must be a program on the server side, which can take the account number, open the database, read the balance and send back the balance; everything automatically. Many languages exist which support this type of implicit operations. One such language is Java. That is, on the server side, you can place a Java program which can connect or open the database and do the needful. This program is known as JDBC program – Java Database Connectivity. JDBC is a Java program and Java technology capable to connect to a database.

Now let us go with technical details of JDBC. JDBC is an acronym for Java Database Connectivity. JDBC is a Java program which can connect to a database and do all the operations what you can perform manually at SQL prompt. That is, without seeing SQL prompt, you can perform all the operations through a Java program like creating a new table and CRUD (create, retrieve, update and delete) operations etc. To do the job, Java comes with JDBC API. JDBC API supports many classes and interfaces like Connection, Statement, ResultSet, DriverManager etc to write a JDBC program.

What is JDBC?

JDBC is an API specification developed by Sun and defines a uniform interface for accessing different relational databases. JDBC is a core part of the Java platform and is included in the standard JDK(J2SE).

Other way to say, JDBC stands for Java Database Connectivity. JDBC provides standard classes and interfaces to access any relational database from a Java program. The same JDBC program works to access any database with a very light modification of driver name.

Advantages of JDBC

Many advantages exist with JDBC from a programmer’s prospective. From a Java program, any database can be accessed existing on any server in the world. This results, for example, a bank branch office can update an account holder’s balance amount available on the server. In realtime, when an account holder goes to an ATM center, draws the amount, a Java program on the server is invoked and this Java program though JDBC, updates the amount; every thing goes automatic without the involvement of a programmer on the scene.

1. JDBC comes with a Universal API that works with every database.
2. JDBC can connect to any vendor specific drivers including ODBC drivers.
3. JDBC is database-independent. The same JDBC application can be used with another database by simply switching to the database specific driver in the code.
4. JDBC meets the demands of an enterprising application that involves connection pooling and distributed transactions.

JDBC Architecture

The JDBC API comes with a DriverManager class and is the fundamental to connect to a database from Java. The DriverManager uses an extra driver that is very specific to connect to a particular database. Following figure illustrates.
image

JDBC is an API that gives the capability, to Java, to access any relational database in a uniform way without affecting many changes in the code. JDBC is positioned as one of the components of J2EE technologies and comes by default with the JDK distribution.

Platform-Independent and Database-Independent

As the figure explains, the Driver Manager connects to a database through an ODBC driver. This ODBC driver is database-dependent but Driver Manager (of Java) is database-independent. When database changes only the ODBC driver link in the Java code is to be changed; but not all the code.

JDBC is platform independent as it is written in Java and database independent as the same JDBC program can connect to any database with minor changes in the code.

4 thoughts on “JDBC Tutorial Introduction”

  1. Could you please explain.
    Say I have 10 records in my table
    ResultSet rs=stmt.executeQuery(“select *from customers”);
    How the records will stored in Java? Will it be a like array of 10 cutomers or 10 objects individually stores.

Leave a Comment

Your email address will not be published.