The introduction of the Java language is required before introducing the concept of JDBC. Java is an object-oriented programming language. It incorporates all the objected-oriented concepts such as polymorphism, abstraction, encapsulation, etc. Java is a platform independent language because it can run on different operating systems. Java syntactically resembles C and C++, but it is simpler than the two, as it does not contain pointers and multiple inheritance. Both pointers and multiple inheritance seem complex to the application developer.
Java has some drawbacks too. It does not provide much facility for developing GUI (graphical user interface) applications. The earlier version of Java did not contain any support for database access. This was the major drawback of this language, as in today’s world, keeping and managing databases is quite important. To remove this drawback, Sun Microsystems has introduced a new interface known as Java Database Connectivity (JDBC). JDBC provides database connectivity to Java applications.
JDBC stands for Java Database Connectivity. It provides database access to Java applications. The JDBC API interfaces are used to connect to the database and execute all types of SQL statements. The JDBC API interfaces can execute normal SQL statements, dynamic SQL statements, and stored procedures that take both IN and OUT parameters. The section below provides a description of various JDBC API interfaces.
Java provides various objects that can be used in Java applications. These objects provide Java with some of the database specific data types available in most databases. The table below describes various JDBC API objects:
| Date | It provides an object that can accept database date values. |
| DriverManager | It provides another way to make a connection to the database. |
| DriverPropertyInfo | It is used to manage Driver objects. |
| Time | It provides an object that can accept database time values. |
| Timestamp | It is used to get the values from the database that are of timestamp data type. |
| Types | It provides a list of predefined integer values that identify the various data types that can be used in JDBC. |
Whenever an error occurs in Java, an exception is thrown. The JDBC API introduces three new exceptions. These exceptions are discussed as follows:
Before the introduction of JDBC, the Java applications used to call and access CGI (Common Gateway Interface) programs through streams in Java. The CGI scripts in Java call a separate program that provides database access and returns results. The CGI approach is slow and allows bugs to get into the applications. In addition to this, one must know both the technologies – Java and CGI – to make applications, whereas to access the database through JDBC, one must be a master in Java only.
Another strong reason to use JDBC is that it provides faster access than the CGI approach. In CGI approach, another program is called that accesses the database, processes the data, and returns the result back to the calling program in a stream. This requires multiple levels of processing that increase wait time and also allow more bugs to creep into the applications.
The figure below demonstrates the way CGI accesses the database.

When a CGI script is called, a new script is executed through a Web server, whereas execution of a JDBC statement against the database requires only some sort of server that passes the SQL commands through to the database. This increases the speed of execution of SQL statements. The CGI script first connects to the database and processes the results, whereas the JDBC allows the connection of the database to Java applications so that it can perform all the processing.
The figure below demonstrates how a JDBC statement is executed:
