Supplement IV.D: Tutorial for MS Access. For Introduction to Java Programming By Y. Daniel Liang



Similar documents
Supplement IV.C: Tutorial for Oracle. For Introduction to Java Programming By Y. Daniel Liang

CS/CE 2336 Computer Science II

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Supplement I.B: Installing and Configuring JDK 1.6

ECLIPSE & Faircom ODBC Driver

Supplement I.B: Installing and Configuring JDK 1.6

ODBC Driver Version 4 Manual

CS2506 Operating Systems II Lab 8, 8 th Tue/03 /2011 Java API

Migrating helpdesk to a new server

Matisse Installation Guide for MS Windows. 10th Edition

Database Assistant. Once Database Assistant is installed you must login to gain access to the database. Copyright 2009

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

FileMaker 12. ODBC and JDBC Guide

Part IV: Java Database Programming

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

FileMaker 13. ODBC and JDBC Guide

FileMaker 11. ODBC and JDBC Guide

Querying Databases Using the DB Query and JDBC Query Nodes

FileMaker 8. Installing FileMaker 8 ODBC and JDBC Client Drivers

Crystal Reports Installation Guide

2. Unzip the file using a program that supports long filenames, such as WinZip. Do not use DOS.

ODBC Reference Guide

Getting Started using the SQuirreL SQL Client

Installation Instruction STATISTICA Enterprise Small Business

Matisse Installation Guide for MS Windows

FileMaker 14. ODBC and JDBC Guide

Siemens Applied Automation Page 1 11/26/03 9:57 PM. Maxum ODBC 3.11

Converting InfoPlus.21 Data to a Microsoft SQL Server 2000 Database

IBM FileNet eforms Designer

SQL and Java. Database Systems Lecture 19 Natasha Alechina

STATISTICA VERSION 12 STATISTICA ENTERPRISE SMALL BUSINESS INSTALLATION INSTRUCTIONS

Using ODBC with MDaemon 6.5

Using SQL Server Management Studio

Setting Up ALERE with Client/Server Data

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

The JAVA Way: JDBC and SQLJ

Java and Databases. COMP514 Distributed Information Systems. Java Database Connectivity. Standards and utilities. Java and Databases

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

TECHNICAL NOTE. The following information is provided as a service to our users, customers, and distributors.

How To Connect A Java To A Microsoft Database To An Ibm.Com Database On A Microsq Server On A Blackberry (Windows) Computer (Windows 2000) On A Powerpoint (Windows 5) On An Ubio.Com

Using Netbeans and the Derby Database for Projects Contents

ODBC Overview and Information

National Fire Incident Reporting System (NFIRS 5.0) Configuration Tool User's Guide

MS Project Tutorial for Senior Design Using Microsoft Project to manage projects

How To Use The Database In Jdbc.Com On A Microsoft Gdbdns.Com (Amd64) On A Pcode (Amd32) On An Ubuntu (Amd66) On Microsoft

CHAPTER 23: USING ODBC

INSTALLING MICROSOFT SQL SERVER AND CONFIGURING REPORTING SERVICES

How to Install Java onto your system

DbSchema Tutorial with Introduction in MongoDB

SonicWALL Global Management System Installation Guide Entry Edition. Version 2.1

Installing Cobra 4.7

MICROSTRATEGY 9.3 Supplement Files Setup Transaction Services for Dashboard and App Developers

Create a Database Driven Application

Oracle Database 10g Express

Voyager Reporting System (VRS) Installation Guide. Revised 5/09/06

Migrating a Database from Legi for Windows 2.X to MS Access

Microsoft Office 2010

Visual Studio.NET Database Projects

Exchanger XML Editor - Data Import

For Introduction to Java Programming, 5E By Y. Daniel Liang

Video Administration Backup and Restore Procedures

Create a New Database in Access 2010

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

Database Forms and Reports Tutorial

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3

Setting up an MS SQL Server for IGSS

CIMHT_006 How to Configure the Database Logger Proficy HMI/SCADA CIMPLICITY

Inmagic ODBC Driver 8.00 Installation and Upgrade Notes

FreeFlow Accxes Print Server V15.0 August P Xerox FreeFlow Accxes Print Server Drivers and Client Tools Software Installation Guide

Datacolor TOOLS. Datacolor TOOLS QCX. Datacolor TOOLS WORKSTATION

How to Configure Outlook Client for Exchange

MICROSOFT ACCESS 2003 TUTORIAL

64-Bit Compatibility with Micromeritics Applications

RE:Open for SQL Anywhere. Installation Guide. RE:Open for SQL Anywhere Installation Guide 1

Newsletter Sign Up Form to Database Tutorial

Chapter 4 Accessing Data

TAMUS Terminal Server Setup BPP SQL/Alva

Using the Query Analyzer

Sync Exchange for MS Access Conduit for Windows Version 4 Manual

Mesa DMS. Once you access the Mesa Document Management link, you will see the following Mesa DMS - Microsoft Internet Explorer" window:

DbSchema Tutorial with Introduction in SQL Databases

CONTACTS SYNCHRONIZER FOR IPAD USER GUIDE

Installation Instruction STATISTICA Enterprise Server

Tutorial on Operations on Database using JDeveloper

CONFIGURING MICROSOFT SQL SERVER REPORTING SERVICES

How to configure the DBxtra Report Web Service on IIS (Internet Information Server)

Tutorial: How to Use SQL Server Management Studio from Home

LAB 1: Getting started with WebMatrix. Introduction. Creating a new database. M1G505190: Introduction to Database Development

Guide to Setting up Docs2Manage using Cloud Services

HAHTsite IDE and IP Installation Guide

National Fire Incident Reporting System (NFIRS 5.0) NFIRS Data Entry/Validation Tool Users Guide

TAMUS Remote Desktop Setup For BPP SQL & Alva

Java. How to install the Java Runtime Environment (JRE)

Stellar Phoenix. SQL Database Repair 6.0. Installation Guide

Transcription:

Supplement IV.D: Tutorial for MS Access For Introduction to Java Programming By Y. Daniel Liang This supplement covers the following topics: Creating Databases and Executing SQL Creating ODBC Data Source Accessing Database Using Java 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. 1 Creating a Database and Executing SQL Here are the steps to create a database and execute SQL statements from Microsoft Access: 1. Launch Microsoft Access database as shown in Figure 1.1. Check Blank Access database in the Create a new database section. Click OK to display the File New Database dialog box, as shown in Figure 1.2. Create and select the directory book in the Save in field and type examplemdb.mdb in the File name field. Click Create to create a new database. The examplemdb database is created as shown in Figure 1.3. 8

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 9

Table dialog box. 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

2 Creating an ODBC Data Source To use the JDBC-ODBC driver to access databases in Java, two drivers must be installed on the client machine: a universal JDBC-ODBC bridge driver and a vendor-specific ODBC driver. The JDBC-ODBC driver comes with Java 2 SDK 1.3 or higher, or any Java development tool that supports JDK 1.2 or higher. The ODBC driver is not included in JDK and is usually provided by database vendors. To access the MS Access database, you have to create an ODBC data source. Here are the steps to create an ODBC data source: 1. Install an MS ODBC driver for MS Access if necessary. By default the ODBC driver is installed on Windows 98, NT, 2000, and XP. If not, install MS Access to get the proper ODBC driver on your system. Upon successful installation, you should see the icon Data Sources (ODBC) in the Administrative Tools window under the control panel for Windows 2000. For Windows 98 and NT, you should see a "32-bit ODBC" icon appearing on the control panel. 2. From the Windows Start button, choose Setting, Control Panel to bring up the Control Panel dialog box. Doubleclick Administrative Tools, and then double-click Data Sources (ODBC) to display the ODBC Data Source Administrator dialog box, as shown in Figure 1.8. 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. 3 Accessing Database Using Java NOTE: you are not familiar with SQL and JDBC, please Chapter 25 on basics of SQL and how to write Java database programs. The JDBC driver for MS Access is sun.jdbc.odbc.jdbcodbcdriver contained in JDK. The database URL for Access is jdbc:odbc:datasource. For example, if the ODBC data source is named examplemdb, the URL is jdbc:odbc:examplemdb. The following is a sample program import java.sql.*; public class SimpleJdbc { public static void main(string[] args) throws SQLException, ClassNotFoundException { // Load the JDBC driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Driver loaded"); // Establish a connection Connection connection = DriverManager.getConnection ("jdbc:odbc.examplemdb"); System.out.println("Database connected"); // Create a statement Statement statement = connection.createstatement(); // Execute a statement ResultSet resultset = statement.executequery ("select firstname, mi, lastname from Student where lastname " + " = 'Smith'"); 14

// Iterate through the result and print the student names while (resultset.next()) System.out.println(resultSet.getString(1) + "\t" + resultset.getstring(2) + "\t" + resultset.getstring(3)); } } // Close the connection connection.close(); 15