Professional Documents
Culture Documents
Tutorial For MS Access
Tutorial For MS Access
0 Introduction
Access is a ubiquitous database running on Microsoft
Windows. It is usually used by a single user. Access
provides an intuitive graphical user interface that enables
you to create tables and insert, update, and delete data
from the windows without using the SQL commands. However, to
develop database applications using Java, you still have to
learn and use SQL. This tutorial demonstrates using SQL with
Access and developing Java programs for Access.
Figure 1.1
You can create a new database or use an existing
database.
Figure 1.2
The File New Database dialog box enables you to specify
a new database.
Figure 1.3
The exampleMDB database is created in
c:\book\exampleMDB.mdb.
NOTE: An Access database is contained in a
single file with a .mdb extension. If you have
an existing database, you can open it without
having to create a new database.
2. Choose Queries in the Objects column and click Create
query in Design View (see Figure 1.3) to display the Query
Design view (see Figure 1.4). Click Close to close the Show
Figure 1.4
The Show Table dialog box must be closed to display the
SQL view.
3. Select SQL View in the SQL combo box (see Figure 1.5) to
display the SQL command window, as shown in Figure 1.6.
4. Type in the statement for creating the State table (see
Figure 1.7) and click the Run toolbar button to execute the
statement.
Figure 1.5
The SQL command window can be displayed by choosing the
SQL View command.
10
Figure 1.6
You can type the SQL command in the Query window and
execute it.
5. Type the following SQL statements and execute them one
statement at a time to create the State table, insert data
into the table and select them from the table. The selection
result is shown in Figure 1.7.
create table State(
name varchar(15) not null,
capital varchar(25),
population integer);
insert into State values ('Georgia', 'Atlanta', 8383915);
insert into State values ('New York', 'Albany', 19011378);
select * from State;
Figure 1.7
The selection result is displayed in a window on
Access.
NOTE: Access cannot execute SQL commands from a
script file. You have to type and execute one
SQL command at a time from the query window.
11
Figure 1.8
The ODBC Data Source Administrator is the main dialog
box to manage the data source and the drivers.
12
3. Click Add to bring up the "Create New Data Source" dialog box, as
shown in Figure 1.9.
Figure 1.9
Select a proper driver for the data source in the
"Create New Data Source" window.
4. Select Microsoft Access Driver and Press Finish to bring the ODBC
Microsoft Access Setup dialog window, as shown in
Figure 1.10. Type exampleMDBDataSource in the Data
Source Name field, and type Liang DB Book MS Access
Database in the Description filed. Click Select to
bring up the Select Database dialog window, as shown in
Figure 1.11.
Figure 1.10
Specify the Data Source Name to associate it with a database
in the ODBC Microsoft Access Setup window.
13
Figure 1.11
Select the physical database file name for the data source
name in the Select Database window.
5. Select exampleMDB.mdb from the directory
c:\book\exampleMDB.mdb. Press OK to close the Select
Database dialog window, click OK to close the ODBC
Microsoft Access Setup window, and click OK to close the
ODBC Data Source Administrator window.
14
15