25-08-2014, 10:28 AM
Java Database Connectivity Seminar Report
Java Database Connectivity.doc (Size: 737.5 KB / Downloads: 15)
Abstract
JDBCT is a JavaT API for executing SQL statements. (As a point of interest, JDBC is a trademarked name and is not an acronym; nevertheless, JDBC is often thought of as standing for "Java Database Connectivity".) It consists of a set of classes and interfaces written in the Java programming language. JDBC provides a standard API for tool/database developers and makes it possible to write database applications using a pure Java API.
Using JDBC, it is easy to send SQL statements to virtually any relational database. In other words, with the JDBC API, it isn't necessary to write one program to access a Sybase database, another program to access an Oracle database, another program to access an Informix database, and so on. One can write a single program using the JDBC API, and the program will be able to send SQL statements to the appropriate database. And, with an application written in the Java programming language, one also doesn't have to worry about writing different applications to run on different platforms. The combination of Java and JDBC lets a programmer write it once and run it anywhere.
JDBC is a Java-based data access technology (Java Standard Edition platform) from Oracle Corporation. This technology is an API for the java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. A JDBC-to-ODBC bridge enables connections to any ODBC-accessible data source in the JVM host environment.
Java Database Connectivity (JDBC) API is the industry standard for database-independent connectivity between the Java programming language and a wide range of databases – SQL databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API provides a call-level API for SQL-based database access.
JDBC Architecture
As we all know now that driver is required to communicate with database.
JDBC API provides classes and interfaces to handle request made by user and response made by database.
Some of the important JDBC API are as under.
DriverManager
Driver
Connection
Statement
PreparedStatement
CallableStatement
ResultSet
DatabaseMetaData
ResultSetMetaData
Here The DriverManager plays an important role in JDBC architecture.
It uses some database specific drivers to communicate our J2EE application to database.
Type 1 Driver: JDBC-ODBC Bridge
The JDBC type 1 driver which is also known as a JDBC-ODBC Bridge is a convert JDBC methods into ODBC function calls.
SunprovidesDBC-ODBCBridgedriverby “sun.jdbc.odbc.JdbcOdbcDriver”.
The driver is a platform dependent because it uses ODBC which is depends on native libraries of the operating system and also the driver needs other installation for example, ODBC must be installed on the computer and the database must support ODBC driver.
Type 1 is the simplest compare to all other driver but it’s a platform specific i.e. only on Microsoft platform.
For type-1 we create the DSN name.
Steps for DSN:
1. Start
2. Control panel
3. Administrator tools
4. Data source odbc
5. System dsn
6. Add
7. Microsoft oracle for odbc
8. Finish
9. ora
The JDBC-ODBC Bridge is use only when there is no PURE-JAVA driver available for a particular database.
The driver is a platform dependent because it uses ODBC which is depends on native libraries of the operating system and also the driver needs other installation for example, ODBC must be installed on the computer and the database must support ODBC driver.
Java DB is Oracle's supported distribution of the open source Apache Derby database. Its ease of use, standards compliance, full feature set, and small footprint make it the ideal database for Java developers. Java DB is written in the Java programming language, providing "write once, run anywhere" portability. It can be embedded in Java applications, requiring zero administration by the developer or user. It can also be used in client server mode. Java DB is fully transactional and provides a standard SQL interface.
The JDBC driver manager is the backbone of the JDB architecture. It actually is quite small and simple; its primary function is to connect Java applications to the correct JDBC driver and then get out of the way
Type 4 Driver: Native-Protocol Driver (Pure Java driver directly connected to database) :-
The JDBC type 4 driver converts JDBC method calls directly into the vendor specific database protocol and in between do not need to be converted any other formatted system so this is the fastest way to communicate quires to DBMS and it is completely written in JAVA because of that this is also known as the “direct to database Pure JAVA driver”.
If we are using type-4 driver in oracle then we need to add jar file to the class path because it was given by third party.
JDBC APIs
If any java application or an applet wants to connect with a database then there are various classes and interfaces available in java.sql package.
Depending on the requirements these classes and interfaces can be used.
Some of them are list out the below which are used to perform the various tasks with database as well as for connection
The Connection interface
The Connection interface used to connect java application with particular database.
After crating the connection with database we can execute SQL statements for that particular connection using object of Connection and retrieve the results.
The interface has few methods that makes changes to the database temporary or permanently.
The some methods are as given below.
Statement Interface
The Statement interface is used for to execute a static query.
It’s a very simple and easy so it also calls a “Simple Statement”.
The statement interface has several methods for execute the SQL statements and also get the appropriate result as per the query sent to the database.
Some of the most common methods are as given below
Literature Survey
Sun Microsystems released JDBC as part of JDK1.1 on February 19, 1997.It has since formed part of the Java Standard Edition.The JDBC classes are contained in the Java package java.sql and javax.sql.
Starting with version 3.1, JDBC has been developed under the Java Community Process. JSR 54 specifies JDBC 3.0 (included in J2SE 1.4), JSR 114 specifies the JDBC Rowset additions, and JSR 221 is the specification of JDBC 4.0 (included in Java SE 6).The latest version, JDBC 4.1, is specified by a maintenance release of JSR 221] and is included in Java SE 7.
We can store our data permanently by using file concept.
If we are using file concept we have some drawbacks.
1. If we want to use file concept we need to know IO package
2. It can store small amount of data,insering deleting updating in files it takes more time.
3. It doesn’t support query language.
4. To overcome all those problems we go for database softwares.
In database s/w the data will be stored permanently.
It supports query lang and takes less time for insertion,deletion,updation,retrieve.
Some of the database s/w are
1. Oracle
2. Mysql
3. Sqlserver
4. Db2.
Now by using our javacode if we want to connect to database we are considered the jdbc.
The JDBC API is the industry standard for database-independent connectivity between the Java programming language and a wide range of databases. The JDBC API provides a call-level API for SQL-based database access. JDBC technology allows you to use the Java programming language to exploit "Write Once, Run Anywhere" capabilities for applications that require access to enterprise data.
Functionality
JDBC allows multiple implementations to exist and be used by the same application. The API provides a mechanism for dynamically loading the correct Java packages and registering them with the JDBC Driver Manager. The Driver Manager is used as a connection factory for creating JDBC connections.
JDBC connections support creating and executing statements. These may be update statements such as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be query statements such as SELECT. Additionally, stored procedures may be invoked through a JDBC connection. JDBC represents statements using one of the following classes:
• Statement – the statement is sent to the database server each and every time.
• PreparedStatement – the statement is cached and then the execution path is pre-determined on the database server allowing it to be executed multiple times in an efficient manner.
• CallableStatement – used for executing stored procedures on the database.
Jdbc with Servlets and jsp’s
Java Servlets, or simply servlets are a set of Java classes that can be used and extended for Web server-side programming provided the Web server supports Java servlets. Basically, the programmer specifies which servlet is to be used to process which request or which type of requests from client. Thus, when a request is received by the Web server, the Web server finds the proper servlet for the request. For example, in an HTML form, its action clause can explicity specify which servlet be invoked to process the data submitted through the form.
JDBC is an application programming interface (JDBC API) that defines a set of standard operations for interacting with relational database management systems (DBMSs). The DBMSs may be located on a remote machine connected to the Internet. In order to access a database under a specific DBMS, for example, PostgreSQL, one must have a driver for that DBMS and the driver must implement JDBC API. JDBC is a trademark name and not an acronym.
With HTML, Servlets, JDBC, and DBMS, we can easily build Web-based three-tier systems -- client, Web server, and database server. HTML is used to design the client-side interface that is to be executed on a Web browser such as Netscape and Internet Explore. Servlets can be employed to do server-side programming and JDBC can be used to interact with a database(s) for the requests from clients. The database(s) may be located on a remote database server
JDBC driver enhancements
Many new features and enhancements have been made to the JDBC drivers in |DB2® Version 8. Among these changes, the biggest change is a new|JDBC driver architecture known as the IBM® DB2 JDBC Universal |Driver. The Universal Driver is an architecture-neutral JDBC driver for|distributed and local DB2 access. The Universal Driver architecture is |independent of any particular JDBC driver-type connectivity or target |platform, which allows for both Type 4 and Type 2 connectivity in a single |driver instance to DB2 platforms. In addition, platform specifics are |abstracted to the lowest layers, so that driver differences among the various |DB2 platforms are minimized. The initial 1.0 release of the |Universal JDBC Driver supports only Type 4 connectitivity, which is based on |an open distributed protocol (known as Distributed Relational Database |Architecture, or DRDA) for cross-platform access to DB2.
Design Implementation
Just as Java was designed to provide platform independence from hardware/software platforms, so too JDBC has been designed to provide some degree of database independence for developers. JDBC is designed to provide a database-neutral API for accessing relational databases from different vendors. Just as a Java application does not need to be aware of the operating system platform on which it is running, so too JDBC has been designed so that the database application can use the same methods to access data regardless of the underlying database product.
JDBC was developed to work with the most common type of database: the relational database. This is not to say that JDBC cannot be used with another type of database. In fact, there are JDBC drivers that allow the API to be used to connect to both high-end, mainframe databases, which are not relational, and to access flat files and spreadsheets as
databases (which are definitely not relational). But the reality is that JDBC is most commonly used with relational databases.
JDBC gives Java developers the power to database-enable virtually any application, on virtually any platform, using virtually any database. In this book, leading JDBC expert Art Taylor combines an expert JDBC tutorial and a definitive API reference that provides thorough and detailed coverage of the new JDBC 3.0 standard. Taylor brings together code examples, design patterns, and expert programming techniques for J2EE programming. Code examples include Web development, GUI programming with Swing, servlets, JSPs, EJBs, and RMI. Coverage includes:
Conclusion
Java, being robust, secure, easy to use, easy to understand, and automatically Downloadable on a network, is an excellent language basis for database applications. What is needed is a way for Java applications to talk to a variety of different databases. JDBC is the mechanism for doing this. JDBC extends what can be done in Java. For example, with Java and the JDBC API, it is possible to publish a web page containing an applet that uses information obtained from a remote database. Or an enterprise can use JDBC to connect all its employees (even if they are using a conglomeration of Windows, Macintosh, and UNIX machines) to one or more internal databases via an intranet
With more and more programmers using the Java programming language, the need for easy database access from Java is continuing to grow. MIS managers like the combination of Java and JDBC because it makes disseminating information easy and economical. Businesses can continue to use their installed databases and access information easily even if it is stored on different database management systems. Development time for new applications is short. Installation and version control are greatly simplified.
The JDBC driver manager is the backbone of the JDB architecture. It actually is quite small and simple; its primary function is to connect Java applications to the correct JDBC driver and then get out of the way