A Division of Pearson Technology Group
201 West 103rd Street, Indianapolis, Indiana 46290
Oracle and Java
Development
Bulusu Lakshman
00 1173 FM 7/24/01 10:31 AM Page i
Oracle and Java Development
Copyright 2002 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a
retrieval system, or transmitted by any means, electronic, mechanical, photo-
copying, recording, or otherwise, without written permission from the pub-
lisher. No patent liability is assumed with respect to the use of the information
contained herein. Although every precaution has been taken in the preparation
of this book, the publisher and author assume no responsibility for errors or
omissions. Nor is any liability assumed for damages resulting from the use of
the information contained herein.
International Standard Book Number: 0-672-32117-3
Library of Congress Catalog Card Number: 00-111030
Printed in the United States of America
First Printing: August 2001
04 03 02 01 4 3 2 1
Trademarks
All terms mentioned in this book that are known to be trademarks or service
marks have been appropriately capitalized. Sams Publishing cannot attest to
the accuracy of this information. Use of a term in this book should not be
regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as
possible, but no warranty or fitness is implied. The information provided is on
an “as is” basis. The author and the publisher shall have neither liability nor
responsibility to any person or entity with respect to any loss or damages aris-
ing from the information contained in this book.
ii
Executive Editor
Rosemarie Graham
Acquisitions Editor
Angela Kozlowski
Development Editor
Kevin Howard
Managing Editor
Charlotte Clapp
Project Editor
Carol Bowers
Copy Editor
Michael Dietsch
Indexer
Rebecca Salerno
Proofreader
Jody Larsen
Technical Editor
Joe Greene
Team Coordinator
Lynne Williams
Interior Designer
Gary Adair
Cover Designer
Alan Clements
Page Layout
Ayanna Lacey
Stacey Richwine-DeRome
00 1173 FM 7/24/01 10:31 AM Page ii
Contents at a Glance
Introduction .................................................................................................1
Part I Introduction
1 Introduction to Oracle Java Technologies
..........................................................4
Part II Database Access in Java
2 Java Stored Procedures
.................................................................................16
3 Basic JDBC Programming
............................................................................52
4 Advanced JDBC Programming
....................................................................100
5 Basic SQLJ Programming
...........................................................................148
6 Advanced SQLJ Programming
.....................................................................188
Part III Building Reusable Java Components
7 Using JavaBeans
.......................................................................................214
8 Using Enterprise JavaBeans
.........................................................................242
9 Developing and Deploying Enterprise JavaBeans
.............................................260
10 Using Business Components for Java (BC4J)—Introduction and Development
.....296
11 Using Business Components for Java (BC4J)—Deployment and Customization
...348
Part IV Employing Java in a Web Environment
12 Java Servlet Programming
...........................................................................376
13 Using Java Server Pages
.............................................................................406
Index.......................................................................................................432
iii
00 1173 FM 7/24/01 10:31 AM Page iii
Table of Contents
Introduction..................................................................................................1
Part I Introduction
1Introduction to Oracle Java Technologies 4
Database Access in Java .................................................................................................6
Java Stored Procedures—PL/SQL Calling Java..................................................6
JDBC—Java Calling SQL and PL/SQL ..............................................................7
SQLJ—Java Calling SQL and PL/SQL...............................................................7
Building Reusable Java Components .............................................................................8
JavaBeans.............................................................................................................8
Enterprise JavaBeans .........................................................................................10
Business Components for Java ..........................................................................11
Employing Java in a Web Environment .......................................................................12
Java Servlets.......................................................................................................12
Java Server Pages...............................................................................................13
Summary.......................................................................................................................14
Part II Database Access in Java
2 Java Stored Procedures 16
Overview of Java Stored Procedures—PL/SQL Calling Java .....................................18
Advantages of Java Stored Procedures.........................................................................19
Comparison of PL/SQL Stored Procedures and Java Stored Procedures ....................19
Developing Java Stored Procedures—An Overview and Case Study .........................20
Case Study .........................................................................................................20
Writing the Java Method ..............................................................................................22
Loading the Java Method into the RDBMS and Resolving External
References .......................................................................................................23
Publishing the Java Method into the RDBMS ..................................................24
Calling the Java Stored Procedure from SQL or PLSQL..................................25
Loading the Java Method into the Oracle 8i Database ................................................25
Using
loadjava................................................................................................25
Resolving External References..........................................................................27
The Manner in Which Files Are Loaded ...........................................................28
iv
00 1173 FM 7/24/01 10:31 AM Page iv
- 1
- 2
前往页