![]() |
|||
![]() ![]() |
![]() |
![]()
|
![]() |
The Data Definition Language for This Example Some keywords are Transact-SQL. You may want to modify the DDL (Data Definition Language) and DML (Data Manipulation Language) for your DBMS. Listing 10-21 shows how to create tables. Listing 10-21: DDL to create the tables for the Bank of Java applet. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create tables %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CREATE TABLE "accounts" ( "acctno" integer NULL, "pincode" varchar(50) NULL, "ownerno" integer NULL, "datecreated" varchar(50) NULL, "balance" float NULL, ); CREATE TABLE "clients" ( "ownerno" integer NULL, "name" varchar(50) NULL, "address" varchar(50) NULL, ); CREATE TABLE "history" ( "tdate" varchar(50) NULL, "acctno" integer NULL, "typetransaction" varchar(20) NULL, "otheracct" integer NULL, "amount" float NULL, "ipaddress" varchar(50) NULL, ); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Reload data %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('1','1111','1','','992800'); INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('2','2222','2','','1257450'); INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('3','3333','3','','320700'); INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('4','4444','4','','8900750'); INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('5','5555','5','','-840'); INSERT INTO "accounts" ("acctno","pincode","ownerno","datecreated","balance") VALUES ('6','6666','6','','999999995904'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('1','Bernard Van Haecke','Brussels, 1000'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('2','John Doe','Imola Circuit, KM83'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('3','Jane Doe','Imola Circuit, KM83'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('4','Santa Claus','North Pole, 1'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('5','Little Duke','Java Island, 1'); INSERT INTO "clients" ("ownerno", "name", "address") VALUES ('6','The Bank','Downtown LA'); INSERT INTO "history" ("tdate","acctno","typetransaction","otheracct","amount","ipaddress") VALUES ('23 Oct 1996 20:30:15 GMT','1','Transfert','4','-1000','localhost/127.0.0.1'); INSERT INTO "history" ("tdate","acctno","typetransaction","otheracct","amount","ipaddress") VALUES ('23 Oct 1996 20:30:15 GMT','4','Received','1','1000','localhost/127.0.0.1'); INSERT INTO "history" ("tdate","acctno","typetransaction","otheracct","amount","ipaddress") VALUES ('24 Oct 1996 21:18:43 GMT','5','Withdraw','0','-20','localhost/127.0.0.1'); At the time of this writing, only the JDBC-ODBC bridge and certain ODBC drivers support transaction isolation. Things may change quickly, and by the time you read this chapter, more drivers will support this feature. Dynamic Database AccessThe next example illustrates how to use JDBCs DatabaseMetaData and ResultSetMetaData methods. A Java Database ExplorerThe Java database explorer example runs as a stand-alone application. It can dynamically discover database content thanks to a very intuitive graphical user interface. Numerous JDBC database metadata methods are exploited to enable the exploration of virtually any relational database management system. The main features of the program are these:
The GUI part of this example was written using Marimba Bongo, which generates a 100-percent portable .gui file. This file contains a persistent form of the widgets used in this example. The .gui file is editable using Marimba Bongo, a demo version of which is on the CD-ROM accompanying this book. The unzipped Marimba classes must be in the CLASSPATH or must be present on the WWW server to run this example. The GUI part of the application uses the Marimba Bongo classes, which are persistified to a portable file. This use is the main reason why almost no GUI code is present in the source. Each GUI control is a Marimba widget that has a name and whose properties are also persistified in the permanent GUI file. The main database explorer window is divided into three areas:
Figure 10-9 depicts the main window of this example.
The ScreensThe following paragraphs explain how the user interacts with this stand-alone Java application. Log in the Database As shown in Figure 10-10, logging into the database engine requires a correct database URL, JDBC driver, user login, and user password. The syntax of the URL is driver-dependant. The login and password are the identification and authorization strings for a particular user in the database management system.
Press Login to log in to the DBMS. Use Logout to disconnect from the database engine without quitting the application. Another JDBC URL may be entered, and the Login button may be pressed again. Logout may be used as a temporary logout or before logging in as another user. Exit logs the user off the database and closes the application. The Navigation Graphical Control The tree widget on the left side controls the whole application and navigates within the database. The Session, Engine, and Objects nodes intensively use database metadata methods to get information from the database. Double-clicking on these tree nodes performs all actions. The resulting data displays in the right window. The main features of this application include:
The tree widget shown in Figure 10-11 controls the whole program.
|
![]() |
|