Input on a New Desktop Java Database Tutorial

by Patrick Keegan

Recently I've found time again to work on actual tutorials. I don't have anything written yet, but I have something resembling a plan, which you can find here: http://wiki.netbeans.org/PlanGuiBuilderDocImprovements.

Over the next few weeks, I'll be blogging about creating a Swing desktop application with database connectivity. These postings will essentially serve as a rough sneak preview of a full-fledged tutorial on the subject that I'll later post to netbeans.org. The tutorial will go beyond simple database connectivity and show things such as one-to-many and many-to-one relationships as well as how to bind database tables to a variety of GUI components. We'll use a MySQL database that has tables for client info, order info, and countries. There will be a one-to-many relationship between the client and order tables. There will be a many-to-one relationship between client and countries tables. Along the way, I'll be looking at any feedback that comes through and do my best to respond to it, whether in quick responses, in separate articles, or by modifying the final tutorial. Chances are that I'll also tweak the structure along the way as I find better ways of doing things.

To start off, I'll provide an SQL script that provides a beginning database structure:

CREATE TABLE CLIENTS (
ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR(20),
SURNAME VARCHAR(30),
ADDRESS VARCHAR(30),
CITY VARCHAR(30),
STATE_ VARCHAR(30),
ZIP INTEGER,
COUNTRY_ID INTEGER,
PHONE INTEGER
);

CREATE TABLE EMAIL_ADDRESSES (
CLIENT_ID INTEGER NOT NULL,
ADDRESS VARCHAR(50) NOT NULL PRIMARY KEY,
FORMAT INTEGER,
FOREIGN KEY (CLIENT_ID) REFERENCES CLIENTS(ID)
);

CREATE TABLE ORDERS (
ID INTEGER NOT NULL AUTO_INCREMENT,
CLIENT_ID INTEGER NOT NULL,
PRODUCT VARCHAR(50) NOT NULL,
AMOUNT INTEGER NOT NULL,
PRIMARY KEY(ID),
FOREIGN KEY (CLIENT_ID) REFERENCES CLIENTS(ID)
);

CREATE TABLE PRODUCTS (
MODEL VARCHAR(50) NOT NULL PRIMARY KEY,
PRICE DECIMAL NOT NULL
);

CREATE TABLE COUNTRIES (
COUNTRY_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
COUNTRY VARCHAR(30)
);

ALTER TABLE CLIENTS
ADD CONSTRAINT COUNTRIES_FK Foreign Key (COUNTRY_ID)
REFERENCES COUNTRIES (COUNTRY_ID);

Read the rest of this tutorial

 

Comments:

where i can get the java database

Posted by muhazir on June 04, 2008 at 10:20 PM PDT #

The Java DB is free and comes with the NetBeans IDE download. NetBeans is also free, and you can download it from http://www.netbeans.org

Dana

Posted by Dana Nourie on June 05, 2008 at 02:21 AM PDT #

Great idea! I look forward to it.

Posted by Tan Nguyen on September 21, 2008 at 08:46 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Java Technology Fundamentals are now covered as part of the Core Java Technology Tech Tips. Please go there for more tech tips.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today