Showing posts with label JDBC. Show all posts
Showing posts with label JDBC. Show all posts

Sunday, September 21, 2008

Elements of JDBC Architecture


1. Client Java Program

There are many kinds of Java programs like Java bean, Applet, Servlet, EJB, Swing window, etc. Whenever, these Java programs are request the DBMS for database operations these are clients with respect to the database server.

Responsibilities of the client Java program

i. Establishing database connection.

ii. Submitting SQL statements to the DBMS based on the business service the program is handling.

iii. Processing the results that come from the database and presenting them to the end user.

iv. Closing the connection when the database operation are complete


2. JDBC API

In Java, methods are stored in class files. These class files are grouped in packages. JDBC library methods are grouped into 2 packages

i. java.sql

ii. javax.sql

Whenever a Java program wants to communicate with the DBMS it has to make use of the JDBC API. To make these library methods available to the Java program, we need to import these packages.

e.g.: import java.sql.*;


3. DriverManager

  • Java program requests the DriverManager for the database connection.
  • DriverManager initiates the connection process on the driver.
  • Driver establishes the connection with the database server and gives the same to the DriverManager.
  • In turn, the DriverManager gives the connection to the Java program.
  • Once the Java client program is connected to the database server, DriverManager’s role ends.

4. Driver

  • A driver is pre-created translation software that enables Java and database communication in heterogeneous environment.
  • A driver developed according to JDBC specification is a JDBC driver.
  • JDBC drivers are written in Java.
  • They implement JDBC API

Responsibilities of a driver

i. Establishing the Java client – database server connectivity.

ii. Receiving the JDBC method calls from the JDBC application, translating them into DBMS understandable calls and forwarding them to the DBMS.

iii. Receiving the results / response from the DBMS, translating them into Java or JDBC format and returning them to the application.

iv. Indicating the end of the database session of the client to the DBMS.

Thursday, September 18, 2008

Introduction to JDBC

In an enterprise application, business data should be stored in a persistent storage area in such a way that it can be retrieved efficiently and in programming language independent manner.

Database Management Systems (DBMSs) allow us to store data permanently in the databases and retrieve it in a language independent way. Databases are good at storing data but poor at processing and presenting it. High level languages like Java are made for data processing and presenting and hence are efficient in this task but poor at storage. Hence these both form integral components of a business application. Since each has a specific role, interaction between them is inevitable.

The strength of Java is its methods. However, to retrieve data from the database these method calls cannot be used. No DBMS is capable of understanding Java method calls. DBMSs use SQL to interact with the database. Java cannot process SQL statements and SQL syntax. These are called heterogeneous environments. Thus, its clear that Java - Database interaction though mandatory, cannot be achieved directly.

What is JDBC?

1. To enable Java - Database communication in heterogeneous environments (such stated above), Sun Microsystems created a technology called JDBC.

2. JDBC is a J2SE technology.

3. JDBC is an API (Application Programming Interface) - a set of library methods that enable Java - Database comunication.

4. JDBC is a specification.

5. JDBC is a service technology.

JDBC is used by any kind of Java program (Servlets, JSP, Applets, Swing, etc) to communicate with any database(Oracle, MS SQL Server, MySQL, Informix, Sybase, etc) in a standard manner.

Any Java program communicating with the database is a JDBC application.