Cover image for Database Programming with JDBC & Java, Second Edition

Book description

Java and databases make a powerful combination. Getting the two sides to work together, however, takes some effort--largely because Java deals in objects while most databases do not.

This book describes the standard Java interfaces that make portable object-oriented access to relational databases possible and offers a robust model for writing applications that are easy to maintain. It introduces the JDBC and RMI packages and uses them to develop three-tier applications (applications divided into a user interface, an object-oriented logic component, and an information store).

The book begins with a quick overview of SQL for developers who may be asked to handle a database for the first time. It then explains how to issue database queries and updates through SQL and JDBC. It also covers the use of stored procedures and other measures to improve efficiency, where these are available.

But the book's key contribution is a set of patterns that let developers isolate critical tasks like object creation, information storage and retrieval, and the committing or aborting of transactions.

The second edition includes more basics of JDBC and SQL, with more examples, and a deeper discussion about the architecture of a robust, maintainable database application. The second edition also explains the relationship between JDBC and Enterprise JavaBeans.

Table of Contents

  1. Database Programming with JDBC and Java, 2nd Edition
    1. Preface
      1. Audience
      2. Using This Book
      3. Software and Versions
      4. Conventions Used in This Book
      5. Comments and Questions
      6. About the Philosophers
      7. Acknowledgments
      8. Feedback for the Author
    2. I. The JDBC API
      1. 1. Java in the Enterprise
        1. The Enterprise
          1. A Business in Need of an Enterprise Solution
          2. Requirements for a True Enterprise System
        2. Java as a Tool for Enterprise Development
          1. The Java APIs and Platform Independence
          2. Internationalization, Localization, and Accessibility
          3. Sharing Business Concepts Across the Business
        3. The Database
          1. How Java Interacts with a Database
            1. SQL
            2. JDBC
            3. Transaction management
          2. Database Technologies
        4. Database Programming with Java
          1. Putting It All Together
      2. 2. Relational Databases and SQL
        1. What Is a Relational Database?
        2. An Introduction to SQL
          1. CREATE
          2. INSERT
          3. UPDATE
          4. DELETE
          5. SELECT
          6. Joins and Subqueries
          7. Transaction Logic
        3. A Note on SQL Versions
      3. 3. Introduction to JDBC
        1. What Is JDBC?
          1. The Structure of JDBC
          2. Databases and Drivers
          3. Alternatives to JDBC
        2. Connecting to the Database
          1. The JDBC Classes for Creating a Connection
        3. Basic Database Access
          1. Basic JDBC Database Access Classes
          2. SQL NULL Versus Java null
          3. Clean Up
          4. Modifying the Database
        4. SQL Datatypes and Java Datatypes
        5. Scrollable Result Sets
          1. Result Set Types
          2. Result Set Navigation
          3. Determining Where You Are
          4. Helping Your Driver with Scrollable Result Sets
        6. The JDBC Support Classes
          1. java.sql.Types
          2. java.sql.SQLException
          3. java.sql.SQLWarning and java.sql.DataTruncation
          4. java.sql.Date, java.sql.Time, and java.sql.Timestamp
        7. A Database Servlet
          1. Getting Configuration Information
          2. Showing Random-Visitor Comments on an HTTP GET
          3. Saving New Comments
            1. Getting parameter values
            2. Generating a new comment ID
            3. Inserting a new comment
      4. 4. Advanced JDBC
        1. Prepared SQL
          1. Prepared Statements
          2. Stored Procedures
        2. Batch Processing
        3. Updatable Result Sets
          1. Updates
          2. Deletes
          3. Inserts
          4. Visibility of Changes
          5. Refreshing Data from the Database
        4. Advanced Datatypes
          1. Blobs and Clobs
          2. Arrays
          3. Other SQL3 Types
          4. Java Types
          5. Type Mapping
        5. Meta-Data
          1. Result Set Meta-Data
          2. Database Meta-Data
          3. Driver Property Information
          4. A Generic Terminal Monitor
      5. 5. The JDBC Optional Package
        1. Data Sources
          1. Naming and Directory Services
        2. Connection Pooling
        3. Rowsets
          1. Configuration
          2. Usage
          3. Rowset Events
        4. Distributed Transactions
    3. II. Applied JDBC
      1. 6. Other Enterprise APIs
        1. Java Naming and Directory Interface
          1. Naming and Directory Services
          2. Object Binding
          3. Object Lookup
        2. Remote Method Invocation
          1. The Structure of RMI
            1. Access to remote objects
            2. Remote interfaces
            3. Stubs and skeletons
            4. The special exception: java.rmi.RemoteException
          2. An Object Server
        3. Object Serialization
        4. Enterprise JavaBeans
          1. EJB Roles
          2. Kinds of Beans
      2. 7. Distributed Application Architecture
        1. Architecture
          1. Strategic Versus Tactical
          2. Architectural Questions
          3. Common Architectures
            1. Two-tier client/server
            2. Two-tier limitations
              1. Fat clients
              2. Object reuse
            3. When to use a two-tier design
            4. Three-tier
              1. Isolated database connectivity
              2. Centralized business processing
              3. Business object presentation
            5. Drawbacks to the three-tier architecture
          4. The Network Application Architecture
        2. Design Patterns
          1. Client Patterns
            1. The model-view-controller pattern
            2. The listener pattern
            3. The distributed listener pattern
          2. Business Patterns
            1. The composite pattern
            2. The factory pattern
          3. Data Access Patterns
            1. The persistence delegate pattern
            2. The memento pattern
        3. The Banking Application
          1. The Business Objects
          2. Persistence
          3. The User Interface
      3. 8. Distributed Component Models
        1. Kinds of Distributed Components
          1. Process-Oriented Components
          2. Persistent Components
        2. Security
          1. Component Security
            1. Authentication
            2. Validation
          2. Network Security
          3. Database Security
        3. Transactions
          1. Transaction Boundaries
          2. Tracking Changes
          3. Other Transaction Management Issues
        4. Lookups and Searches
        5. Entity Relationships
          1. Façades
          2. Collections
      4. 9. Persistence
        1. Database Transactions
        2. Mementos and Delegates
        3. JDBC Persistence
        4. Searches
      5. 10. The User Interface
        1. Swing at a Glance
          1. Model-View-Controller
          2. Threads in Swing
        2. Models for Database Applications
          1. A Two-Tier Model
          2. A Three-Tier Model
        3. Distributed Listeners
        4. Worker Threads
    4. III. Reference
      1. 11. JDBC Reference
        1. Reference
          1. Array
          2. Blob
          3. CallableStatement
          4. Clob
          5. Connection
          6. DatabaseMetaData
          7. Date
          8. Driver
          9. DriverManager
          10. DriverPropertyInfo
          11. PreparedStatement
          12. Ref
          13. ResultSet
          14. ResultSetMetaData
          15. SQLData
          16. SQLInput
          17. SQLOutput
          18. Statement
          19. Struct
          20. Time
          21. Timestamp
          22. Types
      2. 12. The JDBC Optional Package Reference
        1. Reference
          1. ConnectionEvent
          2. ConnectionEventListener
          3. ConnectionPoolDataSource
          4. DataSource
          5. PooledConnection
          6. RowSet
          7. RowSetEvent
          8. RowSetInternal
          9. RowSetListener
          10. RowSetMetaData
          11. RowSetReader
          12. RowSetWriter
          13. XAConnection
          14. XADataSource
    5. Index
    6. Colophon