Tải bản đầy đủ (.pdf) (1,144 trang)

professional oracle 8i application programming with java, pl sql and xml

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.01 MB, 1,144 trang )

www.it-ebooks.info
Professional Oracle 8i
Application Programming
Michael Awai
Matthew Bortniker
John Carnell
Sean Dillon
Drew Erwin
Jaeda Goodman
Bjarki Hólm
Ann Horton
Frank Hubeny
Thomas Kyte
Glenn E. Mitchell II
Kevin Mukhar
Gary Nicol
Daniel O'Connor
Guy Ruth-Hammond
Mario Zucca
Wrox Press Ltd. 


www.it-ebooks.info
Professional Oracle 8i
Application Programming
© 2000 Wrox Press
All rights reserved. No part of this book may be reproduced, stored in a retrieval system or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embodied in critical articles or reviews.
The author and publisher have made every effort in the preparation of this book to ensure the accuracy
of the information. However, the information contained in this book is sold without warranty, either


express or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable for
any damages caused or alleged to be caused either directly or indirectly by this book.
Published by Wrox Press Ltd,
Arden House, 1102 Warwick Road, Acocks Green,
Birmingham, B27 6BH, UK
Printed in Canada
ISBN 1-861004-84-2
www.it-ebooks.info
Trademark Acknowledgements
Wrox has endeavored to provide trademark information about all the companies and products
mentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee the
accuracy of this information.
Credits
Authors Technical Reviewers Author Agents
Michael Awai Duncan Ainsworth Tony Berry
Matthew Bortniker Danny Ayers Velimir Ilic
John Carnell Yogesh Bhandarkar
The Churchill Team Graham Bowden
Project Administrators
Sean Dillon Luis Cabral Cilmara Lion
Drew Erwin Robert Chang Chandima Nethisinghe
Jaeda Goodman Jitendra Chitkara
Bjarki Hólm Daryl Collins
Indexers
Ann Horton Michael Corning Alessandro Ansa
Frank Hubeny Jeremy Crosbie Andrew Criddle
Thomas Kyte Dean Dameron
Glenn E. Mitchell II Robin Dewson
Production Coordinator
Kevin Mukhar Sean Dillon Tom Bartlett

Gary Nicol Drew Erwin
Daniel O'Connor Mark Fehrenbacher
Illustrations
Guy Ruth-Hammond Dario Ferreira Gomes Shabnam Hussain
Mario Zucca Nikolay Fiykov
Frank Hubeny Cover
Contributing Authors
Manzoor Hussain Shelley Frazier
Sandeepan Banerjee Mike Kay
Frank Bell Aakash Kambuj
Proof Readers
Bambi Bellows Doug Kanwischer Chris Smith
Kelly Cox Victor Kolesov Keith Westmoreland
Shekhar Dhupelia Thomas Kyte Agnes Wiggers
Michael Kay Todd Lauinger
Karen Little Production Manager
Technical Architect
Steven Livingston Simon Hardware
Tony Davis Jim MacIntosh
Jennifer McGurk
Technical Editors
Vinay Menon
Fiver Löcker Jon Millard
Jim Molony Brian Peasland
Mohammed Rfaquat Sarma PRKV
Robert Shaw John Roberts
Jordon Saardchit
Managing Editor
Anunaya Shriwastava
Paul Cooper Leslie Tierstein

Raj Vuchatu
Hiroko Wilensky
www.it-ebooks.info
About the Authors
Michael Awai
Michael Awai lives near Charlotte, North Carolina, USA. He is currently a Consulting Partner with a
successful privately owned consulting company. He works as a system architect, helping clients leverage
the Internet, build extranet services and accomplish their application and business integration goals. He
and his partner Karla are currently expecting their first baby and their first Irish wolfhound.
Matthew Bortniker
Matt has been in the computer field since 1982 and is an independent consultant for local businesses
in the Washington DC area and for the US government. Currently his main tasks include upgrading
client server applications to enterprise wide systems written entirely in Visual Basic and utilizing
Oracle and Microsoft technologies. He is the author of Professional VB6 MTS Programming, ISBN
1861002440,and contributing author in Professional Windows DNA, ISBN 1861994451, (both Wrox
Press). He can be reached at
John Carnell
John Carnell has had an obsession with computers since he was twelve years old, working on his
Commodore 64. That obsession never waned and he is currently working as a Senior Systems
Architect for Workscape, a leading provider of Human Resources and and Employee Benefits self-
service solutions. John's favorite topic of discussion, much to his wife's chagrin, is component based
N-tier architectures. John has extensive experience with Microsoft, Oracle and Java N-tier solutions.
He lives in Waukesha, Wisconsin with his wife Janet and his two pups Ladybug and Ginger. John can
be reached at
For my mother Deborah: What I have achieved in my life is a summation of your hard work, dedication, and
most importantly your sacrifices.
And to Janet: You are my inspiration. I love you both.
The Churchill Team
Chandrabhanu Ambatipudi, Ekta Rani Agarwal, John Ipe, and Makarand Kulkarni form the ‘Oracle
supreme & Java dream’ team at Churchill Software Services India (CSSI). CSSI was established in

1996 in Bangalore India as an Oracle offshore development center, by an ex-Oracle UK management
team. Since its inception the center has been serving the UK market with an exclusive focus on the
Oracle platform, meshing cutting edge technologies with established Oracle technologies, and
providing innovative road map solutions for the Internet age.
Sean Dillon
Sean got his start programming a Commodore Vic 20, back in 1980. Trying to program sprites and
word games in the enormous 3.5Kb of user memory was truly a labor of love. He is now a Senior
Oracle Technologist, working for Oracle Corporation based in Reston, Virginia. He has eight years
of experience specializing in database architecture, tuning, web application development, and now
XML-based technologies. Sean is one of the lead designers on Oracle's Web Education Initiative for
children, Think.com. He is also an avid Quake player. Sean lives outside Washington, DC with his
wife, Whitney, and two sons, Jordan and Cameron.
I would like to thank my wife for her never-ending support and encouragement.
www.it-ebooks.info
Drew Erwin
Drew is a technical project leader and has been working with Oracle products for the last nine years.
The last three of those have been dedicated to enterprise application development with the ever
changing and improving Oracle toolset. Outside of work, Drew’s interests include his family, Pam
and Hannah, his Playstation, and traveling.
Jaeda Goodman
Jaeda Goodman is currently working as a Principal Software Engineer for Keane Ltd., the company
who were responsible for the Sun Connect Framework. She has over four years experience working
with Oracle and Java, encompassing everything from data warehousing to EJBs, servlets and JSPs –
and also InfoBus, if anyone needs any advice or consultation about this now esoteric technology.
Jaeda’s non-technical interests include house restoration, American TV imports, and the ability to
make an amazing blue punch, although of course the latter does not mix well with all of the former,
especially InfoBus.
I'd like to dedicate this to everyone who went through the Synchromatic experience with me.
Bjarki Hólm
For more than three years Bjarki has been designing and developing commercial software tools at

SALT Systems, Inc. His work includes the development of SALT Solutions, a website construction
suite built with Java technology. His areas of (technical) interest include Enterprise Java, XML and e-
commerce Oracle applications. In his working and waking hours, Bjarki is studying computer
engineering at the University of Iceland, and with his Wrox authoring on top of this, he tends to get
very little sleep. Bjarki can be reached at
Ann Horton
Ann Horton is the President of Horton Associates, Inc. and has over twelve years experience designing,
developing, and managing Oracle projects. She has worked closely with Oracle Corporation for many
years, is active in the Oracle User Group Community, and is a frequent presenter at ODTUG, IOUG-A,
RMOUG, and ECO conferences. Ann has been extremely active in the Oracle Development Tools User
Group (ODTUG) serving as a member of the Board of Directors, conference chairperson, and paper
selection chair for numerous conferences, and ODTUG Volunteer of the Year for 2000. Ms. Horton has
also worked as an Affiliate Professor for the Regis University evening MSCIS Program since 1992 teaching
database classes to working students in the Denver area. In her spare time, Ann enjoys biking, hiking, bird
watching, and scuba diving with her husband Dean.
Thanks to my husband Dean, my brother Tom, Jim, and Betty, and all my friends who have encouraged me to
participate in this book project!
Frank Hubeny
Frank Hubeny is a certified Oracle 8i DBA and currently works for Experian doing data warehousing.
He has recently worked for WExcel in Chicago where he designed and built databases for web
applications and used the PL/SQL Toolkit extensively.
www.it-ebooks.info
Thomas Kyte
Thomas Kyte is an Oracle professional who works for Oracle Corporation in the US. He specializes
in database architecture, implementation, and tuning. In addition to his regular duties at Oracle, Tom
writes an ongoing article for Oracle Magazine and can be found on the web answering questions via
‘Ask Tom’ on the Oracle Magazine website. Prior to working for Oracle, Tom worked with a
contractor developing database applications and tools using many different commercial database
products. Tom lives in Leesburg VA, USA with his wife Lori and two children, Alan and Megan.
Glenn E. Mitchell II

Glenn E. Mitchell II, who prefers ‘Mitch’, wears many different hats. He is president of .Com
Consulting Group, a computer-consulting firm in Tallahassee, Florida. Mitch is also a faculty
administrator at the University of South Florida in Tampa, Florida, where he directs the State Data
Center on Aging, teaches graduate and undergraduate students, and earns lots of frequent flyer miles.
He also holds a Ph.D. from the University of Iowa. Mitch writes and speaks at conferences
extensively on object-oriented analysis and design, C++, Java, Visual Basic, and Microsoft SQL
Server. When not a busy professional, Mitch is husband to Lillian and dad to Jessica. Lillian is a
veterinarian, whose passion is small animal medicine. Jessica recently became a teen and spends her
spare time alternately studying Latin and listening to pop music.
Mitch wants to dedicate his contribution to his wife, Lillian, who is also a busy professional and tolerates him
spending countless hours in front of the computer.
Kevin Mukhar
Kevin Mukhar is a software engineer who lives and works in Colorado, USA. He spent 12 years in the US
Air Force, where many of his jobs included using computers, but none of them involved writing software.
Still, he managed to dabble in various languages as a hobby, and had enough practical experience to land
a software engineering job when he left the Air Force. For the past two years he has been part of a team
that developed a distributed system to manage and access large amounts of binary data from an Oracle
database. His heroes are Steve McConnell and Philip Greenspun. Now that he has finished writing (part
of) a book, he understands why many married writers thank their spouse; and so, he too, thanks his wife
for tolerating him during the last few months.
Gary Nicol
Gary Nicol is a Senior Consultant within the eBusiness division of Mi Services Group, and has
worked on a number of web-based projects involving integration of Oracle and Microsoft
technologies. Having originally cut his teeth on a Sinclair ZX Spectrum, he took a twisted career
path, via a degree in Electronic Engineering, followed by a brief incarnation as a semiconductor
engineer, before realising that developing software was a much more fun way to spend his working
day. In writing for this book, he has surprised not only himself, but probably a number of his high
school teachers, who would never have believed he was capable of forming a coherent sentence (even
when they could read his handwriting).
www.it-ebooks.info

Daniel O'Connor
Daniel O'Connor is an independent software developer currently working on management applications
using J2EE technologies, including EJB and JSP. He is a member of the board of directors for jBoss.org, an
open-source application server featuring an EJB container. He is one of the authors of the Professional Java
Server Programming J2EE Edition, Wrox Press, ISBN 186199463. He is also a principal of MVCSoft, Inc.,
which provides training and consulting on J2EE application development.
I would like to dedicate my efforts in this book to Christina Coughlin.
Mario Zucca
Some years ago Mario moved from the procedural world to the object-oriented one. Although it was
a difficult step to take he's since fallen in love with Java and J2EE technologies and in particular with
XML-related technologies such as XSL, XPath and SOAP.
I love freedom! I would like to dedicate this book to my daughter Federica. When she reads this book, many of the
technologies will be prehistoric things, but I hope in an even freer world.
www.it-ebooks.info
www.it-ebooks.info
Summary of Contents
Introduction 1
Section I:
The Database 11
Chapter 1: Internet Programming with Oracle 8i 11
Chapter 2:
Enterprise Application Design 31
Chapter 3:
Database Foundations 53
Chapter 4:
Scaling Your Application with Net8 83
Chapter 5:
Enterprise Development with Designer 6i 105
Section II:
PL/SQL and the Web 171

Chapter 6: PL/SQL Development 171
Chapter 7:
PL/SQL Server Pages 207
Chapter 8:
The PL/SQL Web Toolkit 225
Chapter 9:
A Stock Tracker using the PL/SQL Web Toolkit and JavaScript 257
Chapter 10:
Web PL/SQL Application Development Using Designer 6i 291
Section III:
Java 343
Chapter 11: Oracle JVM and Java Stored Procedures 343
Chapter 12:
Oracle Access with JDBC 393
Chapter 13:
Connection Pooling and Caching 453
Chapter 14:
Database Connectivity with SQLJ 501
Chapter 15:
Enterprise JavaBeans and Oracle 557
Chapter 16:
Inside the Database 629
Chapter 17:
Business Components for Java 655
Chapter 18:
A Discussion Forum using PL/SQL and Java 719
Chapter 19:
Overview of Oracle interMedia Text 779
Chapter 20:
Building a Search Engine using Java and interMedia 803

Section IV:
XML 827
Chapter 21: Oracle and XML 827
Chapter 22:
A Case Study in Enterprise Application Development 893
Chapter 23:
Application Integration using SOAP 941
Chapter 24:
Wireless Applications with Oracle Portal-to-Go 1005
Chapter 25:
ASP, XML and Oracle 1049
Section V:
Appendices 1107
Appendix A: Installation Issues 1107
Appendix B:
Java Primer 1145
Appendix C:
XML Primer 1179
Appendix D:
Support, Errata, and p2p.wrox.com 1221
Index 1227
www.it-ebooks.info
Table of Contents
Introduction 1
What this Book is About 1
Who Should Use this Book 2
How this Book is Structured 2
The Database 3
PL/SQL and the Web 3
Java 4

XML 5
Appendices 6
The Tools you Need for this Book 6
Development Kits 6
Web and Application Servers 7
Tools 7
Conventions 7
Customer Support 8
Source Code and Updates 8
Errata 8
Section I: The Database 11
Chapter 1: Internet Programming with Oracle 8i 11
A Brief History of Oracle 12
Versions and Editions of Oracle 8i 13
Programming Support 14
PL/SQL 14
The PL/SQL Web Toolkit 15
PL/SQL Server Pages 16
Traditional Oracle Development Tools 16
Oracle Forms and Reports 16
Oracle Portal 17
Designer 17
www.it-ebooks.info
Table of Contents
ii
Oracle 8i and Java 18
The Oracle Java Virtual Machine 19
Advantages of the Oracle JVM 20
JDK Compatibility 20
Java Stored Procedures 20

Differences between Oracle JVM and JDK 20
The J2EE Framework and Oracle 21
Java Database Connectivity (JDBC) 21
SQLJ 21
Servlets and JavaServer Pages (JSP) 22
Enterprise JavaBeans 22
Remote Method Invocation (RMI) with CORBA and IIOP 23
JDeveloper 23
Business Components for Java (BC4J) 23
Oracle XML Developer's Kit 24
Oracle InterMedia 25
Text Services 25
Imaging, Audio, and Video Services 25
Oracle Spatial Cartridge 25
Oracle 8i and the Internet 26
Internet Application Server (iAS) 26
Oracle iAS Standard Edition 26
Oracle iAS Enterprise Edition 26
9iAS Wireless Edition 26
Oracle HTTP Server 26
Oracle JSP 27
Oracle 8i JVM 27
Portal-to-Go 27
Oracle iCache 27
Summary 28
Chapter 2: Enterprise Application Design 31
The EAD Concept 32
The Evolution to N-Tier Computing 33
Two-Tier Architecture 33
Scalability 34

Hidden Costs 34
Flexibility Issues 34
Three-Tier Architecture 35
Advantages of Three-Tier 36
Reuse of Code 36
Problems with Three-Tier 37
N-Tier Architecture 38
Scalability and Redundancy 40
Integration 41
Adaptability 41
Problems with N-Tier 42
www.it-ebooks.info
Table of Contents
iii
Oracle and EAD 43
PL/SQL Development 43
Java Development 44
Containers and the Middle Tier 45
Services 46
Transaction Management 46
Declarative Security 46
Error Handling 46
Business Logic 46
Scalability 47
Portability 47
When to Use Java 47
The Supporting Cast of Oracle Software 48
XML 48
Communication Issues 49
Summary 49

Chapter 3: Database Foundations 53
Database History 54
Logical Structures 56
Components of an Oracle 8i Database 56
Data Dictionary 56
Internal RDBMS Tables 57
Data Dictionary Tables 57
Data Dictionary Views 57
DBA Views 58
User Views 58
All Views 58
Dynamic Performance Views 58
Oracle Instance 58
Data Files and Tablespaces 59
Blocks 60
Segments 60
Table Segments 60
Index Segments 60
B*Tree Index 61
Reverse Key Indexes 62
Bitmapped Indexes 62
Function-Based Indexes 63
Cluster Segments 63
Table Clusters 63
Hash Clusters 64
Rollback Segments 64
Temporary Segments 64
Extents 64
www.it-ebooks.info
Table of Contents

iv
Oracle 8i Object/Relational Database 65
Object Types 65
Object Columns 66
Object Views 66
Object Table 66
Object Identifier 67
Collections 67
Nested Tables 67
Varrays 68
Oracle Memory Structures 68
System Global Area 68
Shared Pool 69
DB Buffer Cache 70
Redo Log Buffer 71
How Redo Logs Work 72
Program Global Area 73
Background Processes 74
System Monitor (SMON) 74
Process Monitor (PMON) 75
Database Writer (DBWn) 75
Redo Log Writer (LGWR) 75
Checkpoint (CKPT) 76
Optional Processes 76
Redo Log Archiver (ARCH) 76
Recoverer (RECO) 77
Starting an Instance 78
Oracle's Database Initialization File 78
Control Files 79
Recap 79

Summary 81
Chapter 4: Scaling Your Application with Net8 83
What Net8 Does 84
Why Use Net8? 84
Typical Scenarios 85
Two-Tier Client/Server 85
Multi-Tier Client/Server 89
Oracle Connectivity 90
Connecting to a Server 91
The Network Service Name 91
Network Route 91
Global Database Name 91
The Connection Process 91
Bequeathed Sessions to Dedicated Server Processes 92
Redirected Sessions to Existing Server Processes 93
Refused Sessions 95
Disconnecting from a Server 95
www.it-ebooks.info
Table of Contents
v
Data Operations 95
Migrating to Net8 96
Net8 Tuning 96
Net8 Troubleshooting 98
Diagnosing the Network 98
Diagnosing the Server 99
Diagnosing the Client 100
Some Common ORA Errors and What To Do 101
Summary 102
Chapter 5: Enterprise Development with Designer 6i 105

Designer 6i Software Architecture 106
The New Oracle Repository 108
Repository Objects 108
Containers 109
File Objects 110
Version Control 111
Configurations 112
Dependency Analysis 113
Workareas 113
Overview of Designer 6i Tools 114
Setting up the Oracle Repository 116
Enabling Version Control 117
Maintaining Users 117
Administering the Oracle Repository 120
Introducing the Repository Object Navigator (RON) 120
About Wastebaskets 122
Selecting a Repository Workarea 123
Create an Application System Container 123
The Case Study 125
Getting Started 126
Overview 126
Database Design and Development Process Using Designer 128
Develop a Conceptual Data Model of Requirements 128
Case Study Data Requirements 129
Oracle's Entity Relationship Diagramming Conventions 130
Develop the Education Center Entity-Relationship Model 131
Log on to Designer 132
Create an Entity-Relationship Diagram 133
Create the Entities 134
Create the Relationships 136

Add the Attributes 138
Create Domains 140
Assign a Domain to an Attribute 142
Define a Unique Identifier for each Entity 143
Print Entity and Attribute Reports 145
Review the ERD's Quality 146
www.it-ebooks.info
Table of Contents
vi
Transform the Conceptual Data Model into a Preliminary Database Design 148
Select the Run Set for Transformation 148
Select the Settings for Transformation 150
Execute the Database Design Transformer 153
Refine the Database Design 154
Introducing the Design Editor 155
Create a Server Model Diagram 157
Review the Preliminary Database Design 158
Deleting a Preliminary Database Design 158
Revise Each Table's Column Order 159
Define Database Sequences 160
Add Change History Columns 161
Review and Refine Database Constraints and Indexes 163
Print the Revised Server Model Diagram 164
Generate DDL and Create a Physical Database 164
Invoke the Server Model Generator and Select Options 165
Select Objects to Generate 166
Execute the Server Model Generator and Review its Results 167
Execute the Generated DDL 168
Review the Physical Database 168
Summary 169

Section II: PL/SQL and the Web 171
Chapter 6: PL/SQL Development 171
Minimal Development Environment 172
Reference Material 172
Programming Editor 172
Version Control Software 173
SQL Performance Tools 173
Debugging 176
Profiling 176
Testing 177
Programming Style 178
Writing PL/SQL 178
Building a PL/SQL Test Framework 179
Packages 179
Data Packages 180
The ex Exception Package 187
The Test Framework 191
Display Packages 197
Formatting the Display 204
Generating the Report 204
Summary 205
www.it-ebooks.info
Table of Contents
vii
Chapter 7: PL/SQL Server Pages 207
Introduction 207
When to Use PSPs 208
PSP Architecture 208
The Anatomy of a PSP 209
PSP Directives 210

The Page Directive 210
The procedure Directive 211
The parameter Directive 211
The include Directive 212
PSP Declarations 212
PSP Scriptlets 213
PSP Expressions 214
Source for cust_dets.psp 215
Handling Errors in a PSP 219
Loading a PSP into the Database 220
What Now? 221
Summary 222
Chapter 8: The PL/SQL Web Toolkit 225
A Brief History of the Toolkit 226
When to Use the Toolkit 226
The Toolkit Architecture 227
Setting up the Environment 228
Configuring iAS 229
Configuring a Simple Database Access Descriptor (DAD) 230
You Don't Have iAS, You Say? 231
Installing the Toolkit 231
Debugging Your Configuration 233
CGI Environment Not Initialized 233
Improper privileges 234
Can't Resolve Package/Procedure Name 234
Building Applications Using the Toolkit 234
Your First Dynamic Page 235
Nomenclature of a Request 235
Lifecycle of a Request 236
The Toolkit API 238

HTF & HTP 238
OWA_CACHE 239
OWA_COOKIE 239
OWA_CUSTOM 240
www.it-ebooks.info
Table of Contents
viii
OWA_IMAGE 240
OWA_OPT_LOCK 240
OWA 240
OWA_PATTERN 240
OWA_SEC 240
OWA_TEXT 240
OWA_UTIL 240
WPG_DOCLOAD 241
Building the Sample Application 241
The Department Report 241
Changing the Department 243
Showing the User's Detail Record 245
The Departments Procedure, Explained 252
Summary 255
Chapter 9: A Stock Tracker using the PL/SQL Web Toolkit and JavaScript 257
Overview of the Case Study 258
Application Architecture 259
Maintaining State on the Client 259
The User Interfaces 260
Data Model 262
Accounts Table 263
Funds Table 264
Trades 265

Current Value Table 266
Track User Table 266
Loading Initial Data 267
The PL/SQL Packages 268
Backend Data Package 268
The backend Specification 268
The backend Package Body 270
Frontend Display Package 275
Support Files 280
JavaScript: htm.js 281
Javascript: stocks.js 282
Style Sheet: stocks.css 287
Summary 289
www.it-ebooks.info
Table of Contents
ix
Chapter 10: Web PL/SQL Application Development Using Designer 6i 291
Getting Started 292
Overview 292
Designer's Web PL/SQL Application Development Process 294
Setup the Web Application Environment 296
Create an Application Schema 296
Obtain Access to the PL/SQL Web Toolkit 297
Configure Your Webserver 299
Install the Designer Webserver Generator Library 300
Develop the Database Design in Designer 301
Generate DDL and Build the Physical Database 303
Insert Instructor Data into the PERSON Table 303
Extend the Database Design with Application Properties 304
Generate the Table API 308

Introduction to Web PL/SQL Module Design 310
Format of Generated Web PL/SQL Modules 310
Module Component Layout Styles 311
Define Application-Level Generator Preferences 311
Define an Application-Level Preference Set 312
Assign the Preference Set to the Application 314
Using Cascading Stylesheets (Optional Exercise) 314
Design and Generate Web PL/SQL Modules 316
COURSE Module 316
Create the Module Definition 317
Create a Module Component and Table Usages 318
Module Component Display Wizard 320
Use a Module Diagram to Refine the Module Design 320
Define Module Component Preferences for Multi-Row Insert Form 321
Generate and Execute the First Course Module 322
FRCOURSE Module 326
Copy COURSE Module 326
Revise the Module Definition 327
Revise the Module Component 327
Revise the Base Table Usage 327
Revise the Module's Generator Preferences 328
Revise the Module Component Preferences 328
Generate and Execute the FRCOURSE Module 328
MDCOURSE Module 329
Copy COURSE Module 330
Add the CS Module Component 330
Refine the Module Component's Display 333
Create LOV Component 334
Revise the Module's Generator Preferences 336
Generate and Execute the MDCOURSE Module 336

MAIN Module 339
Create the Main Module 339
Generate and Execute the MAIN Module 341
Summary 341
www.it-ebooks.info
Table of Contents
x
Section III: Java 343
Chapter 11: Oracle JVM and Java Stored Procedures 343
Java-enabling Infrastructure 344
The Oracle 8i Java Virtual Machine 345
Java Namespace Implementation 345
Compilers: BCOMP and the Oracle 8i JVM Accelerator (NCOMP) 346
The Resolver 346
JDBC and SQLJ 346
Java Stored Procedures 347
Preparing the Development Environment 348
Identify and Install the Appropriate JDK 348
Use Your JDK Documentation 348
Install Your IDE 349
Check Your Path Environment Variable 349
Developing Stored Procedures in Java 350
A Date-Formatting Function 351
Coding and Compiling the Java Class 351
Editing and Compiling the Code from the Command Line 352
Editing and Compiling the Code in Oracle JDeveloper 352
Examining the Code 354
Simple Debugging with System.out() and System.err() 355
Deploying to the Database 355
Deploying from the Command Line 355

Resolver Syntax 356
Checking Installation Status 356
Other loadjava Options for Class Loading/Resolving 357
Un-installing Java Classes with dropjava 358
Publish a Java Class Using a Call Spec 358
Publishing a Call Spec into an Oracle Package 360
First-time Activation 360
Deploying and Publishing with Oracle JDeveloper 361
A Simple Function Using JDBC to Query Database 364
Editing and Compiling the Code 366
Deploying SalesPerformance from the Command Line 366
Publishing SalesPerformance.getAvgSalesPerf() 366
Java to Oracle Type Mappings 366
Boolean Issues 368
Using OUT and IN OUT Parameters 368
Deploying getAvgSalesPerf() with JDeveloper 372
Calling Stored Procedures from Java Stored Procedures 372
DML and Transactions 374
Restrictions on DML-Enabled Java Stored Procedures 377
Transactions and Sessions in Java Stored Procedures 377
Triggers and Advanced Queuing with Java Stored Procedures 378
Setting up the Queue 379
Coding the Stored Procedure 380
Compiling Using the JDK from the Command Line 383
Loading the Classes and Publishing the Call Spec 383
Defining the Trigger 384
Testing the Solution 384
www.it-ebooks.info
Table of Contents
xi

Returning Query Results as XML 385
Installing XSU 385
Coding the Customer Class 386
Compiling and Deploying the Customer Class 387
DML Operations in XML 388
System Architecture Considerations 390
Performance 390
Features 391
Summary 391
Chapter 12: Oracle Access with JDBC 393
Driver Types 394
Installing JDBC 394
Where to Get Drivers 394
Installing the Oracle JDBC Classes 395
Java Requirements 396
Checking Your Installation 397
JDBC Basics 398
Database Connections 398
Loading a Driver 398
Getting a Connection 402
Commit and Rollback 403
Closing a Connection 404
Statements 404
java.sql.Statement 405
java.sql.PreparedStatement 408
java.sql.CallableStatement 410
Batch Updates 416
Resultsets 424
Getting And Moving Through Resultsets 426
Scrollable Resultsets 427

Retrieving Data from a Resultset 428
Updatable Resultsets 429
MetaData 435
Database MetaData 435
Advanced Topics 436
BLOBs 436
Writing a BLOB from One Table to Another 437
Reading and Writing Binary Data 437
CLOBs 441
Reading and Writing Character Data 442
Reading and Writing Character Data Using Readers and Writers 443
BFILEs 444
Getting a BFILE Locator 444
Using the Bfile Locator to Insert a BFILE 444
Reading BFILE Data 445
Inserting BFILE Data 445
Datasources 446
Summary 450
www.it-ebooks.info
Table of Contents
xii
Chapter 13: Connection Pooling and Caching 453
Pooling 454
Connection Pool Advantages 454
Different Types of Connection Pooling 455
Net8 Connection Pooling 455
Connection Object Pooling 455
Overview 455
Standard Connection Pool 456
Logger 457

DBConnection 458
Instance Variables 458
Constructor 459
Connecting 459
Closing the Connection 460
Database Methods 460
DBConnectionPool 464
Instance Variables 464
Maintaining the Pool of Connections 465
Constructor 466
Monitoring the Connection Pool 467
Getting a Connection From the Pool 469
Returning Connections to the Pool 471
Cleaning Up Resources 471
Managing the Connection Pools 472
Property Files 472
DBPoolManager 474
Client Example 479
Prepare the Database 479
Create the Servlet 480
Deploying the Servlet 483
JDBC 2.0 Connection Pooling 485
New Features 485
DataSource 485
Connection Pooling 486
Oracle JDBC 2.0 Extensions 487
Connection Caching 488
Oracle Connection Cache Implementation 489
Altering the Standard Pool 491
Summary of Updates from JDBC 1.0 491

DBConnection Updates 492
DBConnectionPool Updates 494
DBPoolManager Updates 497
Summary 499
www.it-ebooks.info
Table of Contents
xiii
Chapter 14: Database Connectivity with SQLJ 501
SQLJ Code 502
Executable Statements 502
Host Expressions 503
The Default Connection 506
Oracle.connect() 507
Oracle.getConnection() 508
Closing the Connection 508
A Simple SQLJ Application 509
The Customer Class 510
The User Interface Class 515
Using the SQLJ Translator 518
Basic Translator Operations 519
Profiles 520
Catching SQL Errors 520
Other Basic Operations 521
Advanced Translator Operations 522
Declarations 523
SQLJ Iterators 524
Declaring an Iterator 524
Iterator Examples 525
Creating an Iterator 526
Multiple Row Selection Using Iterators 527

Using the Implements Clause 532
Connection Contexts 535
Connecting to the Same Schema 536
Connecting to Different Schemas 540
Execution Contexts 542
SQLJ in the Server 548
Server vs Client SQLJ 549
SQLJ Runtime Classes 549
The Database Connection 549
Auto-commit 549
The Default Output Device 549
SQLJ Server Example 550
Summary 555
www.it-ebooks.info
Table of Contents
xiv
Chapter 15: Enterprise JavaBeans and Oracle 557
Varieties of EJB Components 559
Where EJBs Fit into Sun's Plans for Server-side Java 560
Do You Need EJB Components in Your Architecture? 562
Resource Acquisition in J2EE Components 563
Transactional Resource Usage 565
Cooperation with Other Enterprise Technologies 567
Constructing EJB Components 568
Introducing the Restaurant Finder Application 568
EJB Components 571
Clients 571
Remote Interfaces 572
PreferenceInterviewer Remote Interface and View Objects 572
PropertyUpdater Remote Interface and Session Bean façades 575

Restaurant Remote Interface 577
Home Interfaces 578
PreferenceInterviewer Home Interface 578
PropertyUpdater Home Interface 579
Restaurant Home Interface, and Entity Create and Finder Methods 579
Entity Primary Keys 581
Implementation Classes 581
PropertyUpdater Implementation Class 583
PreferenceInterviewer Implementation Class 587
Restaurant Implementation Class 591
Deployment Descriptor 605
Deployment 607
Sample Clients 608
A Solution without Entities 612
Deployment Descriptors 621
Deployment 622
Troubleshooting 624
JDeveloper 625
Summary 626
www.it-ebooks.info
Table of Contents
xv
Chapter 16: Inside the Database 629
Why You Really Need to Deal with the Database 630
SQL/92 – A Whole Bunch of Standards 631
Locking Models 634
Concurrency 639
Transactions 641
Tuning Queries 642
Openness 643

Use the Tools the Database Provides 644
SQL_Trace 645
TKPROF 647
Summary 653
Chapter 17: Business Components for Java 655
Components of Oracle BC4J 656
Features of BC4J 657
Encapsulated Business Logic 657
Flexible Views Of Data 658
Transaction Management 658
Developer Productivity 658
Developing with BC4J 658
The Restaurant Example 659
Creating a Database 663
Creating the Database Connections in JDeveloper 664
Creating a Business Components Project using JDeveloper 665
Implementing the Support Classes 666
Class Item 667
Class Order 667
Class OrderLine 668
Class Reservation 669
Class Restaurant 670
Entity Objects 670
Defining Validation and Business Logic 673
Domain Objects 673
Using Domain Objects 674
Step 1: Creating Domain Objects 674
Step 2: Adding Validation Logic 674
Step 3: Binding an Attribute with a Domain 675
Using Built-in Validation Rules 675

Validation Rules 676
Working with Events 677
www.it-ebooks.info

×