JDBC Database Access with Java / Edition 1

JDBC Database Access with Java / Edition 1

by Graham Hamilton, Maydene Fisher, Rick Cattell, Maydene Fisher
     
 

ISBN-10: 0201309955

ISBN-13: 9780201309959

Pub. Date: 08/18/1997

Publisher: Addison-Wesley

JDBC (Java Database Connectivity), the powerful API that is a standard part of the Java Class Libraries (JDK 1.1), represents one of the most exciting and fertile areas for Java development. Offering SQL compatibility and sophisticated database development capabilities, JDBC allows Java programmers access to MIS and Legacy systems.

From the creators of the

Overview

JDBC (Java Database Connectivity), the powerful API that is a standard part of the Java Class Libraries (JDK 1.1), represents one of the most exciting and fertile areas for Java development. Offering SQL compatibility and sophisticated database development capabilities, JDBC allows Java programmers access to MIS and Legacy systems.

From the creators of the JDBC API at JavaSoft, here is the definitive guide to this vital new technology. Appropriate for Java programmers of all skill levels, this book provides explanations of JDBC and Java fundamentals, a step-by-step tutorial to bring you up to speed, and an extensively annotated reference to all JDBC classes and interfaces.

Overviews of Java and the JDBC API explain how JDBC fits into the world of SQL and relational databases. The tutorial walks you through JDBC, demonstrating how to execute common tasks with numerous examples. For those interested in writing applications that access various database systems, the JDBC Metadata API is also introduced.

The alphabetically arranged reference section is comprehensive and detailed, containing class and interface definitions along with a wealth of in-depth information on methods and fields. Also included is important information on mapping Java and SQL types, a look at the rationale behind JDBC's design, and a glimpse into JDBC's future.

Anyone interested in pursuing the many development opportunities made possible by JDBC will find this book an indispensable resource.



Product Details

ISBN-13:
9780201309959
Publisher:
Addison-Wesley
Publication date:
08/18/1997
Series:
Java Series
Pages:
480
Product dimensions:
7.37(w) x 9.08(h) x 0.93(d)

Table of Contents

Acknowledgments v
Part One 3(126)
1 Introduction
3(30)
1.1 Contents of the Book
3(2)
1.2 What Is JDBC?
5(10)
1.2.1 What Does JDBC Do?
6(1)
1.2.2 A Low-level API and a Base for Higher-level APIs
6(1)
1.2.3 JDBC versus ODBC and other APIs
7(1)
1.2.4 Two-tier and Three-tier Models
8(2)
1.2.5 SQL Conformance
10(2)
1.2.6 JDBC Products
12(1)
1.2.7 JavaSoft Framework
12(1)
1.2.8 JDBC Driver Types
12(2)
1.2.9 Obtaining JDBC Drivers
14(1)
1.2.10 Other Products
15(1)
1.3 Java Overview
15(9)
1.3.1 Java Is Portable
15(1)
1.3.2 Java Is Object-Oriented
16(4)
1.3.3 Java Makes It Easy to Write Correct Code
20(1)
1.3.4 Java Includes a Library of Classes and Interfaces
21(1)
1.3.5 Java Is Extensible
22(1)
1.3.6 Java Is Secure
23(1)
1.3.7 Java Performs Well
23(1)
1.3.8 Java Scales Well
24(1)
1.3.9 Java Is Multithreaded
24(1)
1.4 Relational Database Overview
24(9)
1.4.1 Integrity Rules
25(1)
1.4.2 SELECT Statements
26(1)
1.4.3 WHERE Clauses
27(1)
1.4.4 Joins
28(1)
1.4.5 Common SQL Commands
29(1)
1.4.6 Result Sets and Cursors
30(1)
1.4.7 Transactions
30(1)
1.4.8 Stored Procedures
31(1)
1.4.9 Metadata
32(1)
2 Basic Tutorial
33(56)
2.1 Getting Started
33(1)
2.2 Setting Up a Database
34(1)
2.3 Establishing a Connection
35(2)
2.3.1 Loading Drivers
35(1)
2.3.2 Making the Connection
36(1)
2.4 Setting Up Tables
37(5)
2.4.1 Creating a Table
37(3)
2.4.2 Creating JDBC Statements
40(1)
2.4.3 Executing Statements
40(1)
2.4.4 Entering Data into a Table
41(1)
2.5 Getting Data from a Table
42(2)
2.6 Retrieving Values from Result Sets
44(3)
2.6.1 Using the Method next
44(1)
2.6.2 Using the getXXX Methods
44(2)
2.6.3 Using the Method getString
46(1)
2.7 Updating Tables
47(2)
2.8 Milestone: The Basics of JDBC
49(1)
2.9 Using Prepared Statements
49(4)
2.9.1 When to Use a PreparedStatement Object
49(1)
2.9.2 Creating a PreparedStatement Object
50(1)
2.9.3 Supplying Values for PreparedStatement Parameters
50(2)
2.9.4 Using a Loop to Set Values
52(1)
2.9.5 Return Values for the Method executeUpdate
53(1)
2.10 Using Joins
53(2)
2.11 Using Transactions
55(4)
2.11.1 Disabling Auto-commit Mode
56(1)
2.11.2 Committing a Transaction
56(1)
2.11.3 Using Transactions to Preserve Data Integrity
57(1)
2.11.4 When to Call the Method rollback
58(1)
2.12 Stored Procedures
59(2)
2.12.1 SQL Statements for Creating a Stored Procedure
59(1)
2.12.2 Calling a Stored Procedure from JDBC
60(1)
2.13 Creating Complete JDBC Applications
61(6)
2.13.1 Putting Code in a Class Definition
62(1)
2.13.2 Importing Classes to Make Them Visible
62(1)
2.13.3 Using the main Method
63(1)
2.13.4 Using try and catch Blocks
63(1)
2.13.5 Retrieving Exceptions
63(2)
2.13.6 Retrieving Warnings
65(2)
2.14 Running the Sample Applications
67(1)
2.15 Sample Code
68(13)
2.15.1 Sample Code 1 and 2
69(4)
2.15.2 Sample Code 3 and 4
73(4)
2.15.3 Sample Code 5
77(1)
2.15.4 Sample Code 6
78(3)
2.16 Creating an Applet from an Application
81(8)
2.16.1 Writing Applet Code
82(2)
2.16.2 Running an Applet
84(1)
2.16.3 Sample Code 7 and 8
85(4)
3 Metadata Tutorial
89(40)
3.1 Getting Information about a Result Set
89(12)
3.1.1 Using the Method getColumnCount
90(1)
3.1.2 Sample Code 9
90(2)
3.1.3 Using Other ResultSetMetaData Methods
92(1)
3.1.4 Getting Column Type Information
93(1)
3.1.5 Sample Code 10 and 11
94(3)
3.1.6 Sample Code 12
97(3)
3.1.7 Getting Other Information
100(1)
3.2 Getting Information about a Database or Database System
101(15)
3.2.1 Categories of DatabaseMetaData Methods
101(1)
3.2.2 Methods that Return a String
101(2)
3.2.3 Methods that Return an int
103(1)
3.2.4 Methods that Return a boolean
104(1)
3.2.5 Methods that Return a ResultSet Object
104(1)
3.2.6 Sample Code 13
104(2)
3.2.7 Getting Information about DBMS Types
106(1)
3.2.8 Sample Code 14
106(4)
3.2.9 Getting Information about Primary and Foreign Keys
110(1)
3.2.10 Sample Code 15
111(3)
3.2.11 Sample Code 16
114(2)
3.3 A Generic Application
116(13)
3.3.1 Sample Code 17 and 18
117(12)
Part Two 129(272)
4 CallableStatement
129(14)
4.1 CallableStatement Overview
129(5)
4.1.1 Creating a CallableStatement Object
130(1)
4.1.2 IN Parameters
130(1)
4.1.3 OUT Parameters
131(1)
4.1.4 Numbering of Parameters
132(1)
4.1.5 INOUT Parameters
132(1)
4.1.6 Retrieve OUT Parameters after Results
133(1)
4.1.7 Retrieving NULL Values as OUT Parameters
133(1)
4.2 CallableStatement Definition
134(1)
4.3 CallableStatement Methods
134(9)
5 Connection
143(20)
5.1 Connection Overview
143(7)
5.1.1 Opening a Connection
143(1)
5.1.2 URLs in General Use
144(1)
5.1.3 JDBC URLs
145(1)
5.1.4 The odbc Subprotocol
146(1)
5.1.5 Registering Subprotocols
147(1)
5.1.6 Sending SQL Statements
147(1)
5.1.7 Transactions
148(1)
5.1.8 Transaction Isolation Levels
149(1)
5.1.9 Using the Method close to Free DBMS Resources
150(1)
5.2 Connection Interface Definition
150(1)
5.3 Connection Methods
151(10)
5.4 Connection Fields
161(2)
6 DatabaseMetaData
163(84)
6.1 DatabaseMetaData Overview
163(3)
6.1.1 Creating a DatabaseMetaData Object
163(1)
6.1.2 ResultSet Objects as Return Values
164(1)
6.1.3 String Patterns as Arguments
164(2)
6.1.4 Pseudo Columns
166(1)
6.2 DatabaseMetaData Interface Definition
166(7)
6.3 DatabaseMetaData Methods
173(63)
6.4 DatabaseMetaData Fields
236(11)
7 DataTruncation
247(6)
7.1 DataTruncation Overview
247(2)
7.1.1 Data Truncation with No Warning or Exception
247(1)
7.1.2 Data Truncation on Reads
247(1)
7.1.3 Data Truncation on Writes
248(1)
7.1.4 What a DataTruncation Object Contains
248(1)
7.1.5 Retrieving DataTruncation Information
248(1)
7.2 DataTruncation Class Definition
249(1)
7.3 DataTruncation Constructor
249(1)
7.4 DataTruncation Methods
250(3)
8 Date
253(4)
8.1 Date Overview
253(1)
8.1.1 Creating a Date Object
253(1)
8.2 Date Class Definition
254(1)
8.3 Date Constructors
254(1)
8.4 Date Methods
255(2)
9 Driver
257(6)
9.1 Driver Overview
257(2)
9.1.1 Loading and Registering a Driver
257(1)
9.1.2 JDBC Implementation Alternatives
258(1)
9.2 Driver Interface Definition
259(1)
9.3 Driver Methods
259(4)
10 DriverManager
263(10)
10.1 DriverManager Overview
263(3)
10.1.1 Keeping Track of Available Drivers
263(1)
10.1.2 Establishing a Connection
264(1)
10.1.3 DriverManager Methods Are Static
265(1)
10.2 DriverManager Class Definition
266(1)
10.3 DriverManager Methods
266(7)
11 DriverPropertyInfo
273(4)
11.1 DriverPropertyInfo Overview
273(1)
11.1.1 Creating a DriverPropertyInfo Object
273(1)
11.2 DriverPropertyInfo Class Definition
274(1)
11.3 DriverPropertyInfo Constructor
274(1)
11.4 DriverPropertyInfo Variables
275(2)
12 PreparedStatement
277(20)
12.1 PreparedStatement Overview
277(4)
12.1.1 Creating PreparedStatement Objects
278(1)
12.1.2 Passing IN Parameters
278(1)
12.1.3 Data Type Conformance on IN Parameters
279(1)
12.1.4 Using setObject
279(1)
12.1.5 Sending JDBC NULL as an IN parameter
280(1)
12.1.6 Sending Very Large IN Parameters
280(1)
12.2 PreparedStatement Interface Definition
281(1)
12.3 PreparedStatement Methods
282(15)
13 ResultSet
297(22)
13.1 ResultSet Overview
297(6)
13.1.1 Rows and Cursors
298(1)
13.1.2 Retrieving Column Values
298(1)
13.1.3 Datatypes and Conversions
299(2)
13.1.4 Positioned Updates
301(1)
13.1.5 Using Streams for Very Large Row Values
301(1)
13.1.6 NULL Result Values
302(1)
13.1.7 Optional or Multiple Result Sets
303(1)
13.1.8 Closing a ResultSet Object
303(1)
13.2 ResultSet Interface Definition
303(2)
13.3 ResultSet Methods
305(14)
14 ResultSetMetaData
319(12)
14.1 ResultSetMetaData Overview
319(2)
14.1.1 Creating a ResultSetMetaData Object
319(1)
14.1.2 Using ResultSetMetaData
319(2)
14.2 ResultSetMetaData Interface Definition
321(1)
14.3 ResultSetMetaData Methods
321(8)
14.4 ResultSetMetaData Fields
329(2)
15 SQLException
331(6)
15.1 SQLException Overview
331(2)
15.1.1 What an SQLException Object Contains
331(1)
15.1.2 Retrieving SQLException Information
332(1)
15.1.3 What an SQLException Means
332(1)
15.2 SQLException Class Definition
333(1)
15.3 SQLException Constructors
333(1)
15.4 SQLException Methods
335(2)
16 SQLWarning
337(6)
16.1 SQLWarning Overview
337(2)
16.1.1 What an SQLWarning Object Contains
337(1)
16.1.2 Retrieving SQLWarning Information
338(1)
16.2 SQLWarning Class Definition
339(1)
16.3 SQLWarning Constructors
339(2)
16.4 SQLWarning Methods
341(2)
17 Statement
343(20)
17.1 Statement Overview
343(8)
17.1.1 Creating Statement objects
343(1)
17.1.2 Executing Statements Using Statement Objects
344(1)
17.1.3 Statement Completion
345(1)
17.1.4 Closing Statement Objects
345(1)
17.1.5 SQL Escape Syntax in Statement Objects
345(3)
17.1.6 Using the Method execute
348(3)
17.2 Statement Interface Definition
351(1)
17.3 Statement Methods
352(11)
18 Time
363(4)
18.1 Time Overview
363(1)
18.1.1 Creating a Time Object
363(1)
18.2 Time Class Definition
364(1)
18.3 Time Constructors
364(1)
18.4 Time Methods
365(2)
19 Timestamp
367(8)
19.1 Timestamp Overview
367(1)
19.1.1 Creating a Timestamp Object
367(1)
19.2 Timestamp Class Definition
368(1)
19.3 Timestamp Constructors
368(2)
19.4 Timestamp Methods
370(5)
20 Types
375(4)
20.1 Overview of Class Types
375(1)
20.1.1 Using the Constants in Class Types
375(1)
20.1.2 Using the Constant OTHER
376(1)
20.2 Types Class Definition
376(3)
21 Mapping SQL and Java Types
379(22)
21.1 Overview
379(1)
21.2 Mapping SQL Datatypes into Java
379(2)
21.3 JDBC Types
381(7)
21.3.1 CHAR, VARCHAR, LONGVARCHAR
381(1)
21.3.2 BINARY, VARBINARY, LONGVARBINARY
382(1)
21.3.3 BIT
383(1)
21.3.4 TINYINT
383(1)
21.3.5 SMALLINT
384(1)
21.3.6 INTEGER
384(1)
21.3.7 BIGINT
384(1)
21.3.8 REAL
384(1)
21.3.9 DOUBLE
385(1)
21.3.10 FLOAT
385(1)
21.3.11 DECIMAL and NUMERIC
385(1)
21.3.12 DATE, TIME, and TIMESTAMP
386(2)
21.4 Examples of Mapping
388(3)
21.4.1 Simple SQL Statement
388(1)
21.4.2 SQL Statement with IN Parameters
388(1)
21.4.3 SQL Statement with INOUT Parameters
388(3)
21.5 Dynamic Data Access
391(1)
21.6 Tables for Type Mapping
392(9)
21.6.1 JDBC Types Mapped to Java Types
393(1)
21.6.2 Java Types Mapped to JDBC Types
394(1)
21.6.3 JDBC Types Mapped to Java Object Types
395(1)
21.6.4 Java Object Types Mapped to JDBC Types
396(1)
21.6.5 Conversions by setObject
397(1)
21.6.6 Types Retrieved by ResultSet.getXXX Methods
398(1)
21.6.7 Types Mapped to Database-specific SQL Types
399(2)
Appendix A: For Driver Writers
401(14)
A.1 Requirements for All Drivers
401(8)
A.1.1 Implement All Methods in the Interfaces
401(1)
A.1.2 Implement a Special Static Section
402(1)
A.1.3 Support Extensions to SQL-92 Entry Level
403(1)
A.1.4 Support Scalar Functions
404(4)
A.1.5 Provide Locks for Positioned Updates and Deletes
408(1)
A.1.6 Support Multithreading
408(1)
A.1.7 Throw Exceptions for Truncated Input Parameters
409(1)
A.2 Permitted Variants
409(1)
A.2.1 When Functionality Is Not Supported
410(1)
A.2.2 Variation in Fundamental Properties
410(1)
A.2.3 Adding Functionality
410(1)
A.3 Security Responsibilities of Drivers
410(3)
A.3.1 Check Shared TCP Connections
411(1)
A.3.2 Check All Local File Access
412(1)
A.3.3 Assume the Worst
412(1)
A.4 SQLExceptions
413(1)
A.5 Suggested Implementations
413(2)
A.5.1 Prefetch Rows
413(1)
A.5.2 Provide "Finalize" Methods for Applets
413(1)
A.5.3 Avoid Implementation-dependent States
414(1)
Appendix B: JDBC Design
415(8)
B.1 A Bit of History
415(2)
B.1.1 How It Started
415(1)
B.1.2 What Can Be Learned from Our Experience?
416(1)
B.2 Evolution of JDBC
417(3)
B.2.1 ResultSet.getXXX Methods
418(1)
B.2.2 PreparedStatement.setXXX Methods
418(1)
B.2.3 CallableStatement.registerOutParameter Method
418(1)
B.2.4 Support for Large OUT Parameters
418(1)
B.2.5 isNull versus wasNull
419(1)
B.2.6 Java Type Names or JDBC Type Names
419(1)
B.2.7 Scrollable Cursors
420(1)
B.3 Post 1.0 Changes
420(1)
B.3.1 Numeric to Bignum to BigDecimal
420(1)
B.3.2 AutoClose Mode Dropped
421(1)
B.4 The Future of JDBC
421(2)
Glossary 423(8)
Index 431

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >