Search This Blog

Friday 28 June 2013

First Step towards JDBC!

First Step towards JDBC
Introduction
This article introduce you with JDBC and shows you how to create a database application to access the databases. For the shake of simplicity, in very first example Access database and Sun's JDBC-ODBC drivers are used. In the later sections we will show you how to use JDBC from your servlets or JSP pages to create dynamic pages or to store the data received from visitors.
What is JDBC?
Java Database Connectivity or JDBC for short is set of Java API's that enables the developers to create platform and database independent applications in java. The biggest advantage of programming in Java is its platform independence. An application written to access the MS Access database on Win 95/Win NT platform can work on Linux against Oracle database, only by changing the name of driver, provided none of the database calls it makes are vendor specific.
What are JDBC Drivers?
JDBC Drivers are set of classes that enables the Java application to communicate with databases. Java.sql that ships with JDK contains various classes for using relational databases. But these classes do not provide any implementation, only the behaviours are defined. The actual implementaions are done in third-party drivers. Third party vendors implements the java.sql.Driver interface in their database driver.

JDBC Drivers Types
Sun has defined four JDBC driver types. These are:
  1. Type 1: JDBC-ODBC Bridge Driver
    The first type of JDBC dirver is JDBC-ODBC Bridge which provide JDBC access to any ODBC complaint databases through ODBC drivers. Sun's JDBC-ODBC bridge is example of type 1 driver.
  2. Type 2: Native -API Partly - Java Driver
    Type 2 drivers are developed using native code libraries, which were originally designed for accessing the database through C/C++. Here a thin code of Java wrap around the native code and converts JDBC commands to DBMS-specific native calls.
  3. Type 3: JDBC-Net Pure Java Driver
    Type 3 drivers are a three-tier solutions. This type of driver communicates to a middleware component which in turn connects to database and provide database connectivity.
  4. Type 4: Native-Protocol Pure Java Driver
    Type 4 drivers are entirely written in Java that communicate directly with vendor's database through socket connection. Here no translation or middleware layer, are required which improves performance tremendously.

JSF PAGE STRUCTURE

A JSF page has extension .xhtml.

It starts with DTD (Document Type Definition).

                                                      Figure- DTD Example

A DTD contains information about the tags to be used in the whole documents. There is some sort of validation stuff from where the document can be validated.
Then next thing that it contains is the list of libraries so that we can use them in out code.


                                          Figure- JSF Page Example

Figure-  Output of Above Code
As you can see in the above figure that there are few tags in the code. Each of them has some specific meaning and all the user code for a JSF page will be written between them.
For writing code in JSF you need to know the basics of HTML because most of the things in JSF is about HTML only.
You can view following link to see how to create a JSF application.


Enjoy Learning :)