J2SE/J2EE JDBC Technology Introduction
java jdbc technology tutorial
In our daily life we are doing so many important work using computer or mobile applications. To achieve the expected result there is so many technologies and methodologies are implemented into the system. To complete one particular task using a software there is one transaction associated with that task which keeps eye on the each activities to finish the task from start to end as expected without any mistake and data corruption.
⇒ In our programming environment transaction are two types:
1. Static Transaction
2. Dynamic Transaction
Note: Here transaction means performing some operations on data.
⇒ In the real-time application static webpages are implemented with static transaction i.e. user can read only a data published in that page.
⇒ Dynamic web pages are also known as user interacted page i.e. user may supply some amount of data dynamically. In order to develop the dynamic web pages we need a dynamic transaction between user and application.
⇒ To meet this requirement we need a database communication.
⇒ Some of the other case for communicating with database are:
1. Providing data security support for confidential data like passwords, PIN, CVV no etc.
Note: Internally database follows data encryption and decryption technology to protect data from hackers.
2. Providing a data concurrency support that is allowing only one user operation on the data and placing other user operations in queue.
⇒ To communicate our application with database we need some mechanism. So database vendors/companies came up with some libraries that helped to communicate with database.
⇒ In the earlier days to communicate with databases different DB vendor provides their own database dependent libraries.
⇒ The above approach makes the application as tightly dependent to the database. In future enhancements whenever if we migrating from one DB to another we need to import a new DB libraries and this process increases the development time of the application and we unable to deliver the application in time to client.
ODBC came into picture:
⇒ Microsoft has initiated to solve the problems and introduced a unified API for accessing DB servers.
⇒ The ODBC(Open Database Connectivity) is termed to achieve this target.
What is ODBC?
⇒ ODBC is a standard abstraction for application accessing database server.
⇒ To simplify creating the DB independent enterprise application the ODBC connectivity defined a unified API named ODBC API.
⇒ In addition to it also defines standards to implement the driver (component) that can convert the ODBC API calls into the respective database calls.
⇒ The driver library that drives ODBC API towards the DB server is known as ODBC driver.
⇒ The ODBC drivers for the respective DB are implemented by the 3rd party vendors (generally DB vendor) following the ODBC standards.
⇒ For example we have “Oracle ODBC Driver” there is an ODBC dirver that can access the Oracle database server.
Advantages working with ODBC API compared to the DB vendor API:
⇒ Working with ODBC API makes our application DB independent.
⇒ Migration cost of the application form one DB to another will be less in case of working with ODBC API.
Disdvantages of ODBC API:
⇒ We do find few problems with ODBC which makes us to use DB vendor driver.
⇒ The ODBC drivers are more available for Microsoft platform, we rarely find the ODBC drivers for non-Microsoft platforms.
⇒ The database specific new features are not available with the ODBC API.
⇒ In case if we want a Java enterprise application to access the DB server using any of the 3 option discussed, will have problems.
⇒ Making the N/W call directly will increase the development time and cost and is error prone.
⇒ Using the DB vendor driver makes the application DB dependent.
⇒ Using ODBC require to implement native method in our application which is difficult to develop and manage, as well it causes problem for platform in-dependency of our application.
Drawbacks of ODBC according to Java point of view:
⇒ Using JNI(Java Native Interface) we can communicate with ODBC indirectly.
⇒ Depending on JNI increases Java calls to native call conversion and this process increases load on the Java application and that affects performance of the application.
⇒ In translation of Java calls to native calls if any exception exception generated entire application is crashed.
⇒ In this translation process Java program looses all the benefits of Java.
What is the difference between Interface and JNI?
⇒ Java Interface contains only abstract methods prototype it doesn’t have body, it might contain body if the interface is provided as a abstract class in Java language. Whereas JNI contain a native method, and body part of this method is provided using Native language i.e. C or C++.
How JDBC come into picture?
⇒ In order to solve above problems JCP (Java Community Process) designed a special component that can support Front-end application accessing the DB server known as JDBC.
⇒ Such component is responsible to drive our application request to the database server, this is known as driver.
⇒ The JDBC provides power to access the tabular data stored in DB servers.
⇒ As this driver (i.e. component) is designed and implemented by the DB vendor it is known as DB vendor driver.
⇒ This option is simple and convenient to us compared to the first option but this is going make our application database dependent.
⇒ Multiple enterprise application have found a great difficulty because of database dependency.