JDBC in Java | Java Database Connectivity
In this article and in a few upcoming articles, I am going to discuss JDBC in Java Applications with Examples. Java Database Connectivity or in short JDBC is a technology that enables the java program to manipulate data stored in the database. JDBC is a database-related technology given by SUN Microsystems. The use of JDBC technology is to communicate with the database. At the end of this article, you will understand the following pointers in detail.
- Where is Java Used Mostly?
- How Java Database Communication is Possible?
- What is the need for Database communication?
- Drawbacks of ODBC using Java
- Relational Database Concepts
- What is JDBC?
- What is JDBC Application?
- How does JDBC work?
- What is the Purpose of JDBC?
Where is Java Used Mostly?
Java is mostly used in enterprise applications. An enterprise application is also known as a business application. Enterprise is nothing but a business organization. To computerize the business activities of an enterprise, whatever computer application we develop is known as a business or enterprise application. Examples: Bank, insurance companies.
What is the basis for a Business Organization to provide Business data?
Data (technically this is called business data)
What are the Important Features of Enterprise Data?
Enterprise data should be persistent (permanent), secure, and easily retrievable. In an enterprise application, if the data is maintained in the database, then all these features are available to the enterprise data. Every java-based enterprise application is associated with the database.
What is the Limitation of Database?
DBMS is weak in data processing and also weak in providing interaction to the end-user.
What is the contribution of Java to Enterprise applications?
Java is excellent in data processing and providing interaction to the end-user.
What is the Limitation of Java?
Java is weak in holding enterprise data in a persistent, easy, and retrievable manner which means where DBMS is strong JAVA is weak in that area.
Note: For an enterprise application, the front-end capabilities of java, java’s processing capability, and database capability are also required.
General Architecture of Enterprise Application:
In order to process the data and displayed the process data to the end-user, java has to access the data from the database in every Java-based enterprise application.
How Java Database Communication is Possible?
JAVA program only knows method calls and DBMS only knows SQL statements. Both have a heterogeneous environment, they cannot communicate directly. So for communication between the JAVA program and database, we have to use JDBC.
What is the need for Database communication?
- To promote a dynamic interaction between user and application.
- To provide security for user confidential data.
- To protect data from multiple users.
Note: In earlier days to communicate with databases different database vendors provides their own dependent libraries.
The following problems are encountered whenever we import database libraries into our application:
- The application becomes database-dependent tightly.
- In future enhancements migrating from one database to another database is a difficult task.
- It increases the development time and cost of the application also.
To solve the above problem, we need a common library to communicate with any type of database. To meet this requirement, Microsoft in collaboration with IBM, Oracle, and some other third-party companies join as an open community and introduced database-independent technology, i.e., ODBC (Open Database Community).
Benefits of ODBC
It is a language-independent technology because it is implemented in a low-level language or native language. It is a database-independent technology.
Drawbacks of ODBC
ODBC is not directly acceptable in a java application to communicate with the database for the following reasons.
- Non-object oriented (it is procedure-oriented)
- Os dependency (because only on windows platform)
Note: Now ODBC can be used with LINUX also.
Drawbacks of ODBC using Java
Must develop the JNI (Java Native Interface) application to communicate with the ODBC library. In the translation of Java calls to native calls conversion Java programmer loses all the benefits of Java. This translation process increases the load on the application and that affects the performance of the application. To solve this problem, Sun Microsystems introduced a database-independent technology called JDBC.
Relational Database Concepts
An important part of every business is to keep records. We need to keep records of our customers, the employee of our company, the emails, etc. If we want to store the data, we can use any of the following two systems:
- File System
A relational model is a basis for any relational database management system (RDBMS). A relational model has mainly three components:
- A collection of objects or relations.
- Operators that act on the objects or relations.
- Data integrity methods.
- File system means here we store the data in individual text files. But file systems have so many disadvantages as we have to store the same data repeatedly in multiple files (data redundancy).
- The file system does not contain any data sharing
- The file system does not provide security
- No maintenance and integrity in the file system because if we want to modify the data then we have to modify it in multiple files.
- No scalability in the file system which means there is a size limitation problem
- If we want to perform any operation we have to write the program like inserting, deleting, updating, etc.
To keep all the data individually is a quite difficult and hectic job because whenever we need the record of a particular customer or an employee we need to search manually. It takes a lot of time and is still not reliable. Here comes the concept of the database.
A database is an organized collection of information. In the database, we can store the data in the form of tables (structured data). The database resolves all the problems of the file system. The database uses one database language called SQL by which we can easily perform any operations like inserting, deleting, searching, updating, etc. and we don’t need to write any new code.
We have so many databases in the market like Oracle, MySql, point DB, ibmdb2, SQL server, etc. To design a database we need three things:
A table is one of the most important ingredients in designing the database. It is also known as a relation, is a two-dimensional structure used to hold related information. A database consists of one or more tables.
A table contains rows: A row is a collection of instances of one thing, such as the information of one employee.
A table contains the columns: Columns contain all the information of a single type. Each column in a table is a category of information referred to as a field.
What is JDBC?
JDBC is a java based data access technology from Sun Microsystems. JDBC is an open specification that contains rules and guidelines that have to be followed by the vendor for developing JDBC drivers.
The process of interacting with the database from Java Applications is called JDBC. JDBC is a Java API which enables java programs to execute SQL statements. It is an application programming interface that defines how a Java programmer can access the database in tabular format from Java code using a set of standard interfaces and classes written in the Java programming language.
JDBC has been developed under the Java Community Process that allows multiple implementations to exist and be used by the same application. JDBC is an API, which will provide a very good predefined library to connect with databases from JAVA applications in order to perform the basic database operations. In the case of JDBC applications, we will define the database logic and Java applications and we will send a Java represented database logic to the Database Engine. But database engine is unable to execute the Java-represented database logic, it should require the database logic in Query Language Representations. To execute JDBC applications we should require a conversion mechanism to convert the database logic from Java representations to Query Language representations and from Query Language representations to Java representations. In this situation, the required conversion mechanisms are available in the form of software called “Driver”.
What is JDBC Application?
Any java application that is communicating with a database using JDBC is known as a JDBC application.
What is the Purpose of Java Database Connectivity?
Any kind of java program can communicate with any RDBMS implementation (any vendor’s DBMS product) in a standard manner using JDBC. JDBC facilitates java database communication despite the heterogeneity of java and database environments. RDBMS implantation means any vendor’s DBMS product means Microsoft’s SQL Server, Oracle’s MySQL, and IBM’s DB2. To communicate with any kind of RDBMS the standard procedure is the same means the procedure of connectivity is the same.
JDBC helps the programmers to write java applications that manage these three programming activities :
- It helps us to connect to a data source, like a database.
- It helps us in sending queries and updating statements to the database, and
- Retrieving and processing the results received from the database in terms of answering your query.
How does JDBC work?
Developed as an alternative to the C-based ODBC (Open Database Connectivity) API, JDBC (Java Database Connectivity) offers a programming-level interface that handles the mechanics of Java applications communicating with a database or RDBMS.
The JDBC interface consists of two layers:
- The JDBC API supports communication between the Java application and the JDBC manager.
- The JDBC driver supports communication between the JDBC manager and the database driver.
JDBC is the common API that your application code interacts with. Beneath that is the JDBC-compliant driver for the database you are using.
In the next article, I am going to discuss JDBC Architecture in detail. Here, in this article, I try to explain What is JDBC and why we need JDBC in Java applications. I hope you enjoy this Java Database Connectivity article.