Home arrow Java & J2EE arrow Page 2 - The JSP Files (part 5): No Forwarding Address

Dumped! - Java

This week, find out how to connect your JSPs to a database and build dynamic, data-driven Web pages. This primer covers different techniques to select, insert and delete records, and uses a simple Web-based address book to illustrate the Connection, Statement, and ResultSet objects.

TABLE OF CONTENTS:
  1. The JSP Files (part 5): No Forwarding Address
  2. Dumped!
  3. The Scenic Route
  4. One Step At A Time
  5. New Friends
  6. No Forwarding Address
  7. Cleaning Up
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 3
March 19, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
If you're familiar with SQL, you know that there are four basic types of operations possible with a database:

SELECT a record;

INSERT a record;

UPDATE a record;

DELETE a record.

In order to demonstrate these operations, we're going to build a little application that requires each of the functions listed above - an address book which allows multiple users to store and view contact information online.

As always, one of the first things you have to think about when designing a data-driven application is the design of the database (duh!). For this application, we've decided to use a single table called "abook", which contains fields for different types of contact information - address, phone, fax, email address, and the like. Every user in the system has a unique login id, and each record in the database is "owned" by a specific user.

We've put together a "dump file", which lets you create the database tables and initial set of records quickly - we suggest that you import this data into your mySQL database server, as we'll be using it throughout this article.

To import the data, download the dump file and use this command at your mySQL prompt:

$ mysql -u username -p database < dumpfile
Or you could insert the contents manually - here is what you 'll need:

# # Table structure for table 'abook' # DROP TABLE IF EXISTS abook; CREATE TABLE abook ( id int(11) unsigned NOT NULL auto_increment, uid varchar(255) NOT NULL, fname varchar(255) NOT NULL, lname varchar(255) NOT NULL, tel varchar(255), fax varchar(255), email varchar(255), addr text, company varchar(255), comment text, PRIMARY KEY (id) ); # # Dumping data for table 'abook' # INSERT INTO abook (id, uid, fname, lname, tel, fax, email, addr, company, comment) VALUES ( '1', 'john', 'Bugs', 'Bunny', '7376222', '', 'bugs@somedomain.com', 'The Rabbit Hole, Dark Woods, Somewhere On Planet Earth', '', 'Big-ears in da house!'); INSERT INTO abook (id, uid, fname, lname, tel, fax, email, addr, company, comment) VALUES ( '2', 'john', 'Elmer', 'Fudd', '', '7628739', 'fuddman@somedomain.com', '', '', ''); INSERT INTO abook (id, uid, fname, lname, tel, fax, email, addr, company, comment) VALUES ( '3', 'joe', 'Peter', 'Parker', '162627 x34', '', 'webcrawler@somedomain.com', 'Your Friendly Neighbourhood Newspaper', '', 'My spidey-sense is tingling!'); INSERT INTO abook (id, uid, fname, lname, tel, fax, email, addr, company, comment) VALUES ( '4', 'bill', 'Clark', 'Kent', '1-800-SUPERMAN', '', 'superdude@somedomain.com', '', '', 'Is it a bird? Is it a plane?');
This will create a table named "abook" with columns for different types of contact information; these records are owned by three mythical users, "bill", "john" and "joe".

Now check whether or not the data has been successfully imported with a SELECT query (the SELECT SQL statement is used to retrieve information from a database). Enter this at your mySQL command prompt:

mysql> select uid, fname, lname from abook;
which, in English, means "display the columns uid, fname and lname from the address book". Here's what you should see:

+------+-------+--------+ | uid | fname | lname | +------+-------+--------+ | john | Bugs | Bunny | | john | Elmer | Fudd | | joe | Peter | Parker | | bill | Clark | Kent | +------+-------+--------+ 4 rows in set (0.00 sec)


 
 
>>> More Java & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: