Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Ad. Java Unit - I

Ad. Java Unit - I

|Views: 0|Likes:
Published by Vijay Chintapalli

More info:

Published by: Vijay Chintapalli on Aug 24, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Chapter 1Database Connectivity from JAVA ProgramObjective:
Objective of this chapter is to provide comprehensive knowledge on Java Database Programmingusing various techniques to learn and write Java programs for accessing the Database.
The students will be in a position to write their own program for accessing and manipulating anytype of database from Java Programming Languages.
Accessing and updating data present in Databases have always been considered efficienttechnique for developing advanced applications. In Java programming language, this has beenmade possible via various ways and one of them is Java DataBase Connectivity (JDBC). This isthe part of the core Java Applications Program Interfaces (APIs) and provides cross-platform,cross-database access through Java programs. From the developer’s perspective, JDBC is the firststandardized effort to integrate relational databases with Java programs. It is a Java databaseconnectivity API, which is a part of the Java Enterprise APIs from JavaSoft. JDBC has opened allthe relational power that can be mustered to Java applets and applications.
1. 1. JDBC Overview
JDBC is Java database connectivity is a set of relational database objects and methods for interacting with data sources. The JDBC APIs are part of the Enterprise APIs specified byJavaSoft and also are part of all Java Virtual Machine (JVM) implementations. The JDBC designis based on the API over X/Open SQL Call Level Interface (CLI). It is not coincidental thatODBC is also based on the X/Open CLI. The JavaSoft engineers wanted to gain leverage fromthe existing ODBC implementation and development expertise, thus making it easier for Independent Software Vendors (ISVs) and system developers to adopt JDBC. However, ODBC isa C interface to DataBase Management Systems (DBMSes) and it is not readily convertible toJava. Thus, JDBC design followed ODBC in spirit as well in its major abstractions andimplemented the SQL CLI.
It would be appropriate at this point of time to introduce terms such as Data Source andDatabase or DBMS before proceeding further. Even though the word database is in thename JDBC, the form, content, and location of the data is immaterial to the Java programusing JDBC so long as there is a driver for that data. Hence the notation data source todescribe the data is more accurate than Database, DBMS, DB, or just file. In the future,Java devices such as televisions, answering machines, or network computers will access,retrieve, and manipulate different types of data (audio, video, graphics, time series, andso on) from various sources that are not relational databases at all! And much of the datamight not even come from mass storage. For example, the data could be video streamfrom a satellite or audio stream from a telephone.
1.1.1 How does JDBC Work?
The JDBC defines a set of API objects and methods to interact with the underlying database. AJava program first opens a connection to a database, makes a statement object, passes SQLstatements to the DBMS through the statement object and retrieves the results as well asinformation about the result sets. Typically, the JDBC class files and the Java applet/applicationreside in the client and also they could be downloaded from the network. For the fast execution, itis desirable to have the JDBC classes in the client. In contrast, the DBMS and the data source aretypically located in a remote server. The JDBC classes are in the java.sql package and all Java programs use the objects and methods in the java.sql package to read from and write to datasources. A program using the JDBC will require a driver for the data source with which it wantsto interface. This driver can be a native module or it can be a Java program that talks to a server in the network using some RPC or a HTTP talker-listener protocol. It is conceivable that anapplication will deal with more than one data source-possibly heterogeneous data sources. For this reason, JDBC has a DriverManager whose function is to manage the drivers and provide alist of currently loaded drivers to the application programs.
1.1.2 JDBC Classes - Overview
When you look at the class hierarchy and methods associated with it, the topmost class in thehierarchy is the DriverManager. The DriverManager keeps the driver information, stateinformation, and more. When each driver is loaded, it registers with the DriverManager andselects the appropriate driver depending on the JDBC URL. The JDBC identifies a database with
a URL and is in the form of 
 jdbc:<subprotocol>:<subname related to the DBMS/Protocol>
.For databases on the Internet/intranet, the subname can contain the Net URL
.The <subprotocol> can be any name that a database understands. The odbc subprotocol name isreserved for ODBC style data sources. A normal ODBC database JDBC URL looks like
 jdbc:odbc:<ODBC DSN>;User=<username>;PW=<password>
.If we develop a JDBC driver with a new subprotocol, it is better to reserve the subprotocol namewith JavaSoft, which maintains an informal subprotocol registry. The java.sql.Driver class isusually referred for information such as PropertyInfo, version number, and so on. So, the classcould be loaded many times during the execution of a Java program using the JDBC API. TheDriverManager returns a Connection object when you use the getConnection() method. Other useful methods include the registerDriver(), deRegister(), and getDrivers() methods. By using thegetDrivers() method, you can get a list of registered drivers.Figure 1.1. View of JDBC Communication Layer 

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->