Professional Documents
Culture Documents
Bhagwan Mahavir Polytechnic: No. Date Topic Grade Sign
Bhagwan Mahavir Polytechnic: No. Date Topic Grade Sign
2 Draw ten red circles in a vertical column in the center of the applet.
Built an applet that displays a horizontal rectangle in its center. Let the
3
rectangle fill with color from left to right.
Write an applet that display the position of the mouse at the upper left
4 corner of the applet when it is dragged or moved. draw a 10x10 pixel
rectangle filed with black at the current mouse position.
Write an applet that contains one button. Initialize the label on the
5 button to “start”, when the user presses the button change the label
between these two values each time the button is pressed.
Write an applet that uses the mouse listener, which overrides only two
6
methods which are mousePressed and mouseReleased.
Write a program that has only one button in the frame, clicking on the
button cycles through the colors: red->green->blue-> and so on.one
7
color change per click.(use getBackGround() method to get the current
color)
Write a program to present a set of choice for user to select a product &
13
display the price of product.
Write a simple JSP program for user Registration & then control will be
16
transfer it into second page.
Write a simple JSP program for user login form with static & dynamic
17
database
JDBC stands for Java Database Connectivity, which is a standard Java API for database-independent
connectivity between the Java programming language and a wide range of databases.
The JDBC library includes APIs for each of the tasks commonly associated with database usage:
Fundamentally, JDBC is a specification that provides a complete set of interfaces that allows for portable
access to an underlying database. Java can be used to write different types of executables, such as:
Java Applications
Java Applets
Java Servlets
JDBC uses a simple class hierarchy for database objects. The classes are contained in the java.sql.*
package, which will be included in JDK 1.1. The java.sql.* classes are descriptions of classes and
methods that must be written in order to produce a J DBC driver, as mentioned earlier.
Three classes relate to opening a connection to the DBMC: java.sql.DriverManager,
java.sql.Connection, and java.sql.DatabaseMetaData. For accessing a database, a java.sql.Connection
object has to be obtained directly from the JDBC management layer and the java.sql.DriverManager.
The following is an example of the code to obtain a connection:
Connection con = DriverManager.getConnection ("jdbc:odbc:wombat", "login", "password");
The DriverManager uses the URL string as an argument, and the JDBC management layer locates
and loads the appropriate driver for the target database to which the applet is attempting to link. The
DriverManager does this by querying each driver, locatin g the one that can connect to the URL. The
drivers look at the URL to determine if it requires a sub-protocol that the driver supports. Then, the
driver connects to the remote database, returning the correct java.sql connection object that is the
way by w hich the applet accesses services on the database. The JDBC management layer must know
the location of each and every database driver available to it. Each driver must register with the
DriverManager using the DriverManager.RegisterDrive method so that th e DriverManager knows
that the driver exists and where to find it.
The DatabaseMetaData returns information about the client ?s connection and interesting
information about the database to which the client has connected.
The java.sql.Statement class is used to compose and execute SQL queries on the DBMS. A query of
some sort, either a select statement, or an insert, update or delete statement could be performed after
connecting. The results of a query are used to creat e a java.sql.ResultSet. Using the connection
obtained in the example above, an example of the code for a Select statement could be:
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while ( rs.next() ) { int x = getInt("a");
String s = getString("b");
float f = getFloat("c"); }
Stored procedures on a database can also be executed with two subclasses of java.sql.Statement:
java.sql.PreparedStatement, and java.sql.CallableStatement.
Finally other JDBC classes are supplied for utility purposes. For example java.sql.Types encapsulates
Java types for database use; java.sql.Date, java.sql.Time, and java.sql.TimeStamp; java.sql.Exception,
and java.sql.Warning provide for exception hand ling.
JDBC Driver Types
JDBC drivers fit into one of the following four categories:
The JDBC-ODBC Bridge plus ODBC driver
Because many PC-based networks already use ODBC for their C and C++ clients, JavaSoft and
Intersolv (a major ODBC driver vendor) worked together to produce a JDBC-ODBC bridge, to make
the transition from C/C++ clients to Java clients more appropriate. It was developed in mid-1996.
They are preparing for the release of a reference implementation of JDBC that uses the ODBC
interface. This is the technology that lets Java Applets use existing ODBC drivers.
In this case, ODBC acts as a mediating layer between the JDBC driver and the vendor client libraries.
The bridge driver translates JDBC method calls into ODBC function calls. ODBC binary code, and in
many cases database client code, must be loaded on e ach client machine that uses this driver. This
kind of driver is most appropriate on a corporate network where client installations are not a major
problem.
Native-API partly-Java driver
This kind of driver is a two-tier driver that converts JDBC calls into calls on the client API for
Oracle, Sybase, Informix, or other DBMS. As well as with the bridge driver, some binary code must
be loaded on each client machine. There is a wide range of variation between vendors in how much
of the driver is Java, and how much is C/C++. This driver connects the client to the DBMS by way
of the vendor-supplied libraries for the DBMS. By this fact, the need for ODBC and the ODBC-
JDBC bridge is not there anymore.
The advantage of using this kind of JDBC driver is that it reduces the complexity of a client
application, including development, debugging, and maintenance time. It also provides direct access
to the full functionality of the database. The client libr aries are usually written in C or C++, therefore,
the JDBC implementation must use a layer of C or C++ in order to make calls to the vendor libraries;
their layer of non-Java code requires the use of "native methods" in Java. JDBC drivers that use
native methods can�t currently be used in applets for security reasons.
JDBC-Net pure Java driver
This driver translates JDBC calls into a DBMS-independent net protocol which is then translated to a DBMS
protocol by a server. This driver designed for a three-tier environment, work with an intermediate application server,
the DBMS-independent net pr otocol, that sits between the client and Native-protocol pure Java driver
This kind of driver converts JDBC calls into the network protocol used by DBMSs directly. This
pure-Java drivers make no calls to the client libraries of the DBMS, but rather communicate with the
DBMS directly, using its proprietary protocol. This allo ws a direct call from the client machine to
the DBMS server and is a practical solution for Intranet access.
Other Features
In addition to retrieving text data, JDBC provides facilities to access binary large objects
(BLOBs). This facility is convenient for moving image, video, and audio information from relational
databases into Java applets or applications. JDBC will supp ort advanced database features as well,
such as using scalar functions and invoking stored procedures and triggers.
JDBC provides threading, which is important for increasing performance because it allows multiple
transactions on database data. Using a three-tier JDBC driver with a robust, pure-Java intermediate
server will bring the added advantages of Java'� thread support. The client can operate as a
multithreaded application and let the intermediate server handle the synchronization and waiting that
results from communicating with a single-threaded client library.
JDBC is a low-level API and a base for higher-level APIs. Two higher-level APIs under development
are:
1. an embedded SQL for Java. JDBC requires that the SQL statements be passed as Strings to Java
methods. An embedded SQL preprocessor allows a programmer to instead mix SQL statements
directly with Java: for example, a Java variable can be used in a SQ L statement to receive or provide
SQL values. The embedded SQL preprocessor then translates this Java/SQL mix into Java with JDBC
calls.
2. a direct mapping of relational database tables to Java classes. This is an object/relational mapping,
in which each row of the table becomes an instance of that class, and each column value corresponds
to an attribute of that instance. Programmer’s c an then operate directly on Java objects; the required
SQL calls to fetch and store data are automatically generated "beneath the covers". More
sophisticated mappings are also provided, for example, where rows of multiple tables are combined in
a Java class.
In addition to retrieving text data, JDBC provides facilities to access binary large objects (BLOBs).
This facility is convenient for moving image, video, and audio information from relational databases
into Java applets or applications. JDBC will supp ort advanced database features as well, such as
using scalar functions and invoking stored procedures and triggers.
JDBC provides threading, which is important for increasing performance because it allows multiple
transactions on database data. Using a three-tier JDBC driver with a robust, pure-Java intermediate
server will bring the added advantages of Java'� thread support. The client can operate as a
multithreaded application and let the intermediate server handle the synchronization and waiting that
results from communicating with a single-threaded client library.
JDBC is a low-level API and a base for higher-level APIs. Two higher-level APIs under development
are:
1. an embedded SQL for Java. JDBC requires that the SQL statements be passed as Strings to Java
methods. An embedded SQL preprocessor allows a programmer to instead mix SQL statements
directly with Java: for example, a Java variable can be used in a SQ L statement to receive or provide
SQL values. The embedded SQL preprocessor then translates this Java/SQL mix into Java with JDBC
calls. the DBMS. This net server middleware is able to connect its pure Java clients to many different
databases. In general, this is the most flexible JDBC alternative.
2. a direct mapping of relational database tables to Java classes. This is an object/relational mapping,
in which each row of the table becomes an instance of that class, and each column value corresponds
to an attribute of that instance. Programmer’s c an then operate directly on Java objects; the required
SQL calls to fetch and store data are automatically generated "beneath the covers". More
sophisticated mappings are also provided, for example, where rows of multiple tables are combined in
a Java cla ss.