JDBC: Database Programming with J2EE

JDBC: Database Programming with J2EE

by Art Taylor

Paperback(BK&CD-ROM)

$42.08 $49.99 Save 16% Current price is $42.08, Original price is $49.99. You Save 16%.

Overview

JDBC gives Java developers the power to database-enable virtually any application, on virtually any platform, using virtually any database. In this book, leading JDBC expert Art Taylor combines an expert JDBC tutorial and a definitive API reference that provides thorough and detailed coverage of the new JDBC 3.0 standard. Taylor brings together code examples, design patterns, and expert programming techniques for J2EE programming. Code examples include Web development, GUI programming with Swing, servlets, JSPs, EJBs, and RMI.

Product Details

ISBN-13: 9780130453235
Publisher: Pearson Education
Publication date: 08/26/2002
Edition description: BK&CD-ROM
Pages: 752
Product dimensions: 7.02(w) x 9.28(h) x 1.07(d)

Table of Contents

PrefaceXXV
Chapter 1JDBC Today1
Introduction1
JDBC Design2
The Relational Database2
Java and Relational Databases2
Object Databases3
Object-Relational Mapping Tools and JDO3
Relational Databases and SQL4
The JDBC API5
Programming for Today7
Java Design Patterns9
Summary11
Coming Up Next12
Chapter 2The Relational Database and SQL13
Introduction13
Relational Database Concepts14
Entities, Attributes, and Relationships14
Normalization17
Creating the Database Tables17
Relational Database Terminology18
Structured Query Language20
Transactions, Database Logging and Isolation Levels, and Concurrency30
SQL Query Optimization34
Dynamic SQL Execution35
Summary36
Coming Up Next36
Chapter 3The JDBC API Explained37
Introduction37
Purpose38
The Structure of JDBC38
History of JDBC Revisions39
SQL Escape Syntax40
The JDBC Code Structure41
JDBC Example47
Summary51
Coming Up Next51
Chapter 4Getting Connected53
Introduction53
Loading the Database Driver53
JNDI and Name Spaces56
JNDI and DataSources59
Loading JDBC Drivers with the DriverManager60
Creating a Connection Using a DataSource66
The javax.sql.DataSource Class69
How Connection Pooling Works72
The XADataSource Interface73
Summary74
Coming Up Next75
Chapter 5Using the Connection77
Introduction77
The java.sql.Connection Class78
The close Method81
The getAutoCommit and setAutoCommit Methods83
The commit and rollback Methods84
The clearWarnings and getWarnings Methods86
The createStatement Method88
The getCatalog and setCatalog Methods92
The getMetaData Method92
The getTypeMap and setTypeMap Methods93
The getTransactionIsolation and setTransactionIsolation Methods94
The isClosed Method95
The isReadOnly and setReadOnly Methods96
The prepareCall Method97
The prepareStatement Method98
The nativeSQL Method99
The PooledConnection Interface99
The XAConnection Interface100
Summary100
Coming Up Next101
Chapter 6Retrieving and Manipulating Data: The Statement Class and JDBC Exceptions103
Introduction103
Processing Data104
The Statement Class110
Executing the Query113
Working with Batches115
Examining Query Results117
Controlling and Tuning Results Processing119
Controlling Query Processing121
Miscellaneous and Utility122
Exceptions and Errors and Warnings126
Summary130
Coming Up Next131
Chapter 7The PreparedStatement and CallableStatement Classes133
Introduction133
The PreparedStatement Class134
The CallableStatement Class159
Summary163
Coming Up Next163
Chapter 8The ResultSet Class165
Introduction165
Using a ResultSet for Serial Access166
Moving in the ResultSet178
Using Updateable ResultSets186
ResultSet Constants197
Data Type Mapping197
Summary201
Coming Up Next201
Chapter 9Transactions in JDBC203
Introduction203
The ACID Principle203
Using Transactions in JDBC204
Distributed Transactions in J2EE210
Declarative Transactions with J2EE213
Distributed Transactions Under the Covers214
Summary216
Coming Up Next216
Chapter 10JDBC and Dynamic Queries217
Introduction217
Using Dynamic Queries218
A Sample Dynamic Query Application: DynamicQuery.java218
The JDBCTypeMapper Class: JDBC to Java Type Mapping232
The ResultSetMetaData Class236
Summary243
Coming Up Next244
Chapter 11The DatabaseMetaData Interface245
Introduction245
DatabaseMetaData Interface: Demonstration Application246
The DBInfoGUI Application: Constructor and buildGUI Method251
Summary265
Coming Up Next265
Chapter 12DatabaseMetaData Methods267
Introduction267
Summary298
Coming Up Next298
Chapter 13Advanced Topics JDBC in Action: Introduction to JDBC Design Patterns299
Introduction299
Using Java Design Patterns with JDBC300
Design Patterns303
Two-Tiered Example: The Table Browser Application307
The Data Access Object: The GeneralDAO Class309
The GeneralAggregateVO Class321
Extending GeneralDAO and GeneralAggregateVO to Create Specific Implementations337
Summary337
Coming Up Next338
Chapter 14Table Browser Application339
Introduction339
The Table Browser Application339
Technical Approach341
The TableBrowser.java Application: the dataTableModel Inner Class356
Three-Tiered RMI Example: The Table Browser Remote Application358
Summary364
Coming Up Next364
Chapter 15Persisting Data Objects with JDBC365
Introduction365
Why Persist Standard Java Objects366
The Object Persistence Example367
The ObjectExample1 Class368
Alternative Techniques377
Summary377
Coming Up Next378
Chapter 16JDBC Design Patterns: Data Access Objects and Value Objects379
Introduction379
DAOs Description380
Code Example: The Simple DAO--CategoryDAO380
Value Object Examples391
A Database Utility Class: DBUtil392
A Complex DAO: The Knowledge_baseDAO Class400
Summary424
Coming Up Next425
Chapter 17JSP Basics427
Introduction427
Some JSP Examples428
Java Software Components: JavaBeans and EJBs431
Using JavaBeans with JSPs432
JavaBeans Versus Custom Tag Libraries440
Using Custom Tags in JSP447
JavaBeans or Custom Tag Libraries: Tips on Usage454
Summary455
Coming Up Next455
Chapter 18JSP and JDBC in Development: A Discussion Group System457
Introduction457
Discussion Group System: Application Description458
The Message458
Application Flow for the Message System461
The Message System: Technical Description470
Message System Database Design474
Summary480
Coming Up Next480
Chapter 19JSP and JDBC in Development: Coding the Discussion Group System481
Introduction481
The Organization of the Discussion Group System481
The Rest of the Story: JSP Pages and JavaBeans Code Explained494
Summary544
Coming Up Next544
Chapter 20Transforming JDBC Data to XML545
Introduction545
Why Perform Transformation546
JDBC to XML: The Conversion Class546
JDBC to XML: The Servlet551
The ServletExample1 Class: The web.xml File558
Summary562
Coming Up Next563
Chapter 21JDBC and BLOBs565
Introduction565
The Benefits of the BLOB565
The BlobView Servlet566
The BlobWriter Class569
The ListMovies JSP Page574
The MoviesBean JavaBean577
Summary581
Coming Up Next581
Chapter 22Enterprise JavaBeans Architecture583
Introduction583
EJBs Defined584
Scalability and Failover584
EJBs585
EJBs and Transactions589
Developing EJBs590
Summary599
Coming Up Next599
Chapter 23JDBC and Enterprise JavaBeans601
Introduction601
JDBC in EJBs601
Connecting EJBs to Presentation Tier Components603
The ServletExample2 Class Declaration604
The MoviesFacadeBean Class610
The MoviesEntityBean EJB616
The MoviesBean JavaBean618
The MoviesEntityBean Class621
The Deployment Descriptor629
Summary630
Appendix AJDBC 3.0631
Introduction631
Retrieving Auto-Incremented Values631
ResultSet Holdability634
Setting Save Points635
Appendix BJava Servlets637
Introduction637
The Network: TCP/IP637
The Network: HTTP640
The HTML Standard643
Servlet Example655
The ServletExample1 Class: The web.xml File663
Appendix CXML Basics and Processing with JAXP667
Introduction667
Uses of XML668
What It is and What It Isn't668
XML: Applying Order to Data669
XML Standards673
Java XML Packages674
The XML Document675
Elements in an XML Document676
Describing the XML Document: The DTD680
JAXP Overview683
Appendix DMath Functions697
Index701

Introduction

About This Book

This book was written with two major goals: cover the JDBC specification in detail and provide a series of examples that demonstrate how JDBC would be used in real world using J2EE.

These goals create two targets: one which is clear and focused and the other which is open-ended and vague. Writing about the JDBC API is fairly straightforward; take the classes, describe the methods and show examples that use the methods in the class. But writing about any possible Java database application is open-ended. A database application can be a text-based application reading from a file and updating a database. It can be an applet written using AWT, a GUI client written in Swing, or it can be a servlet or JSP page running in a Web server. It can be a distributed component written as an EJB.

So showing every possible Java database application was not an option. What was chosen were a set of examples that cover some common and some interesting approaches to Java database programming with J2EE. The result was a set of applications that included text-based applications, RMI, Java file i/o, the Swing GUI, Java Server Pages, Java servlets, JavaBeans and Enterprise JavaBeans.

With that in mind, this book is designed to accommodate the introductory developer, the Java developer who has just started working with Java, up to the intermediate and even advanced Java developer. The book begins by assuming some knowledge of Java and relational databases and presents a series of short examples and a few code snippets. The initial examples are not meant to be representative of how JDBC would be used in a complete application, but are meant to show specific JDBC APIfeatures and methods. By using short examples with most of the work being done within the main program block, the focus in these early chapters remains on the JDBC API and is not lost in a complex application.

Examples begin to progress in complexity with the later chapters. This is obviously based on the assumption that the reader is now more familiar with JDBC and database programming with Java and is ready to see JDBC in more complex, real-world examples. As mentioned previously, these later examples use Swing, RMI, JSPs, JavaBeans, servlets and EJBs and apply various Java design patterns to provide additional structure to the code.

This book covers the majority of the JDBC 3.0 specification. Examples were compiled and tested using JDK 1.4 using JDBC drivers based on the JDBC 2.1 specification.

The code examples in the book are available on the companion web site in addition to other code examples and content. Be sure to check the web site to keep up to date on any corrections, changes or additional content.

Who Should Read This Book

The individual who should read this book should be familiar with the Java language but there is no requirement to be a Java guru. Instead, some knowledge of the language basics, familiarity with the syntax, understanding of object-oriented programming, Java exception handling, and class file layout should be sufficient.

The individual reading this book should also have some understanding of relational databases. Since the assumption is that the potential reader will most likely be a Java programmer who has had a JDBC project thrust upon them (or has wisely pursued such a project), the book will devote some coverage to relational databases in Chapter 2. The SQL language will be covered, including the basic syntax of Data Manipulation Language (DML) and some of the more advanced SQL features such as unions and complex joins.

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews