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



Similar documents
Supplement IV.D: Tutorial for MS Access. 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

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

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

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

Database Access from a Programming Language:

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

Tutorial on Operations on Database using JDeveloper

Uploads from client PC's to mercury are not enabled for security reasons.

Oracle Database 10g Express

LAE 5.1. Windows Server Installation Guide. Version 1.0

Developing SQL and PL/SQL with JDeveloper

SonicWALL Global Management System Installation Guide Entry Edition. Version 2.1

CS 377 Database Systems SQL Programming. Li Xiong Department of Mathematics and Computer Science Emory University

JDBC (Java / SQL Programming) CS 377: Database Systems

IIS, FTP Server and Windows

Database Programming. Week *Some of the slides in this lecture are created by Prof. Ian Horrocks from University of Oxford

Working with Office Applications and ProjectWise

Part IV: Java Database Programming

Supplement IV.E: Tutorial for Tomcat. For Introduction to Java Programming By Y. Daniel Liang

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

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Building Java Servlets with Oracle JDeveloper

Creating PL/SQL Blocks. Copyright 2007, Oracle. All rights reserved.

Installing The SysAidTM Server Locally

Perceptive Intelligent Capture Solution Configration Manager

How To Use A Sas Server On A Java Computer Or A Java.Net Computer (Sas) On A Microsoft Microsoft Server (Sasa) On An Ipo (Sauge) Or A Microsas (Sask

SQL and Java. Database Systems Lecture 19 Natasha Alechina

INSTALLATION INSTRUCTIONS FOR THE STUDENT SAMPLE SCHEMA

Using Microsoft Windows Authentication for Microsoft SQL Server Connections in Data Archive

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

2. Follow the installation directions and install the server on ccc

OpenLane 5.3 supports a distributed architecture with either an Oracle 8i SQL database or a Sybase database. Refer to: Oracle Integration on page 2.

Volume SYSLOG JUNCTION. User s Guide. User s Guide

Brekeke SIP Server Version 3 Using a Third-Party Database Tutorial Brekeke Software, Inc.

Create a Database Driven Application

Secure Global Desktop (SGD)

A basic create statement for a simple student table would look like the following.

Configuring an Alternative Database for SAS Web Infrastructure Platform Services

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Working With Derby. Version 10.2 Derby Document build: December 11, 2006, 7:06:09 AM (PST)

Changing Your Cameleon Server IP

Abstract. Introduction. Web Technology and Thin Clients. What s New in Java Version 1.1

Oracle Call Center Applications Setup

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

Install BA Server with Your Own BA Repository

Implementing the Shop with EJB

Browser Client 2.0 Admin Guide

Getting Started using the SQuirreL SQL Client

Elluminate Live! Access Guide. Page 1 of 7

Software Engineering I CS524 Professor Dr. Liang Sheldon X. Liang

CHAPTER 3. Relational Database Management System: Oracle. 3.1 COMPANY Database

Configure Single Sign on Between Domino and WPS

CS346: Database Programming.

How to Install Java onto your system

Mapping ITS s File Server Folder to Mosaic Windows to Publish a Website

Setting up the Oracle Warehouse Builder Project. Topics. Overview. Purpose

SOA Software API Gateway Appliance 7.1.x Administration Guide

We begin with a number of definitions, and follow through to the conclusion of the installation.

CSCI110 Exercise 4: Database - MySQL

Oracle Fusion Middleware

Elluminate Live! Access Guide. Page 1 of 7

Brazil + JDBC Juin 2001, douin@cnam.fr

Oracle Universal Content Management

NGASI AppServer Manager SaaS/ASP Hosting Automation for Cloud Computing Administrator and User Guide

AXIOM 4 AXIOM SERVER GUIDE

A Brief Introduction to MySQL

Acunetix Web Vulnerability Scanner. Getting Started. By Acunetix Ltd.

Setting up SQL Translation Framework OBE for Database 12cR1

How to use SURA in three simple steps:

Security Correlation Server Quick Installation Guide

Tutorial for Spring DAO with JDBC

Marcum LLP MFT Guide

DbSchema Tutorial with Introduction in MongoDB

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Accessing Oracle 11g from SAS on Linux Using DataDirect Connect for ODBC

Charter Business Phone. Online Control Panel Getting Started Guide. Document Version 1.0

Configuring.NET based Applications in Internet Information Server to use Virtual Clocks from Time Machine

Witango Application Server 6. Installation Guide for OS X

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

How do I use Citrix Staff Remote Desktop

How to Re-Direct Mobile Visitors to Your Library s Mobile App

Installing Oracle 12c Enterprise on Windows 7 64-Bit

MySQL quick start guide

Installation Instruction STATISTICA Enterprise Server

Upgrading Redwood Engine Software. Version 2.0.x to 3.1.0

MySQL Quick Start Guide

Course Objectives. Database Applications. External applications. Course Objectives Interfacing. Mixing two worlds. Two approaches

Tutorial: Using HortonWorks Sandbox 2.3 on Amazon Web Services

FileMaker 12. ODBC and JDBC Guide

Tableau Server Trusted Authentication

How to connect to the University of Exeter VPN service

Microsoft SQL Server Features that can be used with the IBM i

Using SQL Developer. Copyright 2008, Oracle. All rights reserved.

MySQL Quick Start Guide

Novell Identity Manager

Transcription:

Supplement IV.C: Tutorial for Oracle For Introduction to Java Programming By Y. Daniel Liang This supplement covers the following topics: Connecting and Using Oracle Creating User Accounts Accessing Oracle using Java NOTE: Please use Oracle 10.g or high with this tutorial. 0 Introduction Oracle 10g Enterprise runs on Windows 2000, Linux and Solaris. It can support multiple users concurrently on the network. Students can access an Oracle 10g from a Web browser without installing any Oracle software. 1 Connecting and Using Oracle There are many ways to access Oracle. The easiest is to use isql*plus, which enables you to access Oracle from a Web browser. It requires no installation by the user. Suppose an Oracle 10g Enterprise database has been installed on the host liang.armstrong.edu with HTTP server enabled, the user can access it from a Web browser using the URL http://liang.armstrong.edu:5560/isqlplus, as shown in Figure 1.1. 8

Figure 1.1 You can start isql*plus from a Web browser. Enter the username (e.g., scott) and password (e.g., tiger) and click Log In to log into the database. The isql*plus user interface is shown in Figure 1.2. Figure 1.2 You can enter SQL statements, save a SQL script, and load SQL script from isql*plus. Enter the following SQL statements in the Enter Statement text box and click the Execute button. The execution result is displayed on the work screen, as shown in Figure 1.3. 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; commit; The commit statement ends the current transaction and makes permanent all changes performed in the transaction. 9

Figure 1.3 The execution result of the SQL statements is displayed in the work screen. You can choose the Output type to display the result in the work screen, file, or a separate window. You can save the statements in a script file by clicking the Save Script button. You can load the script file from the local client by clicking the Browse button. Another way to access Oracle is through SQL*Plus. You have to first install SQL*Plus on your computer. If Oracle database is also installed on your machine, you can access it by typing sqlplus scott/tiger from the command window. If Oracle database is on a different machine, you need to create an Oracle network service name for the remote database. Figure 1.4 shows an example of using SQL*Plus to access the oracle database on the host liang.armstrong.edu. The alias name for the database is liangorcl. 10

Figure 1.4 You can start SQL*Plus from the DOS command prompt. If you have typing errors, you have to retype the whole command. To avoid retyping the whole command, you can save the command in a file, and then run the command from the file. To do so, type edit filename.sql from the SQL command prompt as shown in Figure 1.5. This command invokes Windows Notepad as shown in Figure 1.6. Type SQL commands in the Notepad and save and exit Notepad. To comment a line, precede with two dashes. You can now run the script file by typing @filename.sql, as shown in Figure 1.7. Figure 1.5 You can use the edit command to launch an editor. Figure 1.6 11

You can save the SQL commands using Notepad. Figure 1.7 You can run the SQL commands in a script file from Oracle. As shown in Figure 1.7, an error is generated when the create table statement is executed, because the table already exists. The insert statements cause errors because they violate the primary key constraint. 2 Creating User Accounts If you are the administrator of the database, you can create accounts for other user to access the database. You may login as a DBA and use the following SQL statements to create a user (e.g., jones). create user jones identified by tiger; grant connect, resource to jones; 3 Accessing Oracle Using Java NOTE: If you are not familiar with SQL and JDBC, see Chapter 30 on basics of SQL and how to write Java database programs. The JDBC driver for Oracle is 12

oracle.jdbc.driver.oracledriver contained in c:\book\classes12.jar. To run a Java program that accesses an Oracle database, you must put classes12.jar in the classpath. The database URL for Oracle is jdbc:oracle:thin:@hostname:port#:oracledbsid. For example, if the database is named orcl on host liang.armstrong.edu on port 1521, the URL is jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl. 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("oracle.jdbc.driver.OracleDriver"); System.out.println("Driver loaded"); // Establish a connection Connection connection = DriverManager.getConnection ("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl", "scott", "tiger"); 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'"); // 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(); 13