JDBC and Java database programming books: A comparative review

Find out which of these 7 books make it through our wringer -- er, reviewer -- in one piece

I've assembled quite a list of candidates in this topic area. The following seven books were available for review at the time of this writing:

  • Database Programming with JDBC and Java by George Reese (O'Reilly)
  • Java Database Programming by Brian Jepson (Wiley)
  • JDBC Database Access with Java: A Tutorial and Annotated Reference by Graham Hamilton, Rick Catell, and Maydene Fisher (Addison-Wesley)
  • Java Database Programming with JDBC (2nd ed) by Pratik Patel and Karl Moss (Coriolis)
  • SQL Database Programming with Java by Bill McCarty (Coriolis)
  • Teach Yourself Database Programming with JDBC in 21 Days by Ashton Hobbs (SAMS Net)
  • JDBC Developer's Resource: Database Programming on the Internet by Art Taylor (Prentice-Hall)

A table providing a bird's-eye view of each title's main characteristics is available.

Database Programming with JDBC and Java

Database Programming with JDBC and Java is the smallest and least expensive book in this month's line-up, but it aims higher than all the rest. In fact, a much more accurate title for this book would have been "Three-Tiered Distributed Java Database Application Development with JDBC and RMI." The bulk of the book revolves around a single, large, and complex example: A three-tiered banking application. Most authors pack their books with half a dozen medium-size examples for a better chance of satisfying more readers. George Reese gambles everything on his one, and unfortunately, his high-risk strategy will not pay off for most readers. The sheer complexity of the banking application, and the number of chapters it is spread across (most of the book), is such that most readers will find this book a struggle to exploit. Indeed, in terms of learning curve, this book resembles a steep mountain that leads to a high plateau. If you fail to follow the author up the mountain, you'll never see the plateau where all the real action is.

Available from Computer Literacy

Concretely, the author employs state-of-the-art software techniques to put together his banking application, relying on a choreographed mix of modularity, cleverly deployed design patterns, strong decoupling, multithreading, transaction management, object locking and persistence, and distributed objects. Reese also explains all about JDBC, en passant. All this packed into a mere 167 pages. The remainder of the book (roughly 60 pages) is allocated to the index and a JDBC and RMI reference (although for RMI, there is only a partial reference). It goes without saying that with so little maneuvering room, explanations are kept brief. While an entire JDBC summary and tutorial can be compressed into a small space (simply because of JDBC's inherent simplicity), RMI's complexity requires more than the claustrophobic few pages Reese allows. Worse, the chronic lack of room seriously undermines the critical explanations behind the banking application's subtly interconnected sub-systems. A lot of the code is necessarily left unexplained while Reese concentrates on explaining the top-level essence of his featured application (the approach being very reminiscent of O'Reilly's original Java hit: Java in a Nutshell). Thankfully the code is of professional quality: thoroughly (and well) commented, consistently laid out, and readable.

The API reference section would be fine if it wasn't for serious corner-cutting. Here's how the author explains why none of the DatabaseMetaData methods are covered: "The DatabaseMetaData class consists of 130+ methods relating mostly to obscure information about the database being used. I have therefore decided to leave out detailed descriptions of them to save on what would mostly be wasted space." DatabaseMetaData happens to be a key interface (not a class) that allows you to write truly DBMS-independent programs, so sweeping this huge interface under the carpet doesn't win any points from me.

Java Database Programming

The Golden Rule of books is never to judge a book by its cover. In this case, it's the title that is misleading. You would expect this book to concentrate on teaching the skills every average database


programmer needs; instead, the author spends a great deal of time implementing JDBC drivers and even an SQL engine. Luckily for the author, his focus on the mechanics of JDBC is an asset, not a liability. Unfortunately for the author, the information on implementing drivers is the only thing going for his book, apart from a better-than-average "Introduction to Databases and Database Design" (Chapter 2).

The writing is often poor or confusing. Here's an example: "The only time when this [String] is correctly populated is when the SQL is executed throw sqlexec(String s); when it is read from System.in via the sqlexec() method, it cannot be captured in this fashion." (Eh?)

Available from Computer Literacy

Clear explanations are hard to find, even on a much larger scale. For example, in Chapter 6 "Inside the tinySQL Database Management System" the author doesn't give the reader any overview (of substance) of the software's structure before diving into the microscopic details of the code. On the plus side, I'll give him credit for employing the Java equivalents of lex and yacc to machine-generate the Java lexical analyzer and parser for his SQL engine. In the next chapter, "The tinySQL JDBC Driver," he makes the same mistake; skipping any kind of high-level introduction to the design of the driver, he dumps almost 80 pages of listings (interleaved with just a little explanatory text) on his readers. Thankfully, the listings are readable (clean, consistent layout, good comments).

Chapter 9 ".mSQL and MsqlJava" really surprised me. Here the author ignores JDBC completely and shows you how to use mSQL, a non-Java shareware SQL engine, through MsqlJava (a set of Java classes to access mSQL). Admittedly, Jepson's Java Database Programming does not sell itself as a JDBC-only book, but to show a technique that locks Java programmers into a proprietary DBMS product, while JDBC's sole purpose in life is to provide SQL database independence, is surely a mistake of some proportion.

Finally, this book's API reference section is almost useless in practice. Its pages don't give a clue about which class or interface the methods you're viewing belong to. To look up any API item, you'll need to go to the index.

And as icing on the cake, once you have located the sought after method, the typesetting makes the information an ordeal to read (three types of fonts, inappropriate choice of point sizes, and wholly counterproductive box shading).

JDBC Database Access with Java: A Tutorial and Annotated Reference

This is the JDBC book that emanates from the proverbial horse's mouth, and Addison-Wesley makes sure it capitalizes on that fact by splashing "The ONLY Books Authorized by JavaSoft" across the front cover. The publishers really needn't have worried about competition for this book:

JDBC Database Access with Java: A Tutorial and Annotated Reference

is the safest (that is, most accurate) JDBC API reference you'll find, and its excellent tutorial puts most other JDBC books to shame.

Chapter 1 introduces JDBC from the rare perspective of the handful of JavaSoft engineers who were responsible for its design and implementation. The same chapter also reiterates Java's major strengths, no doubt to convince the few remaining corporate application programmers that there are no rational reasons for not investing in Java, especially in the fields of database applications. This chapter also includes a brief but adequate relational database/SQL refresher section.

Available from Computer Literacy

The tutorial part of the book, Part One, is spread over some 100 pages and is split into two chapters: "Basic Tutorial" and "Metadata Tutorial." Together these chapters really manage to cover all the JDBC you are likely to need (unless you need to write your own driver). The tutorial achieves its goal in so few pages because it is very well written; uses code snippets to introduce new methods or techniques; lists only a few, carefully selected compilable programs; and skips large application examples altogether. The lack of real-life application examples is not really surprising because this book's prime purpose is to be the last word on the JDBC API, and not one that builds on JDBC to create database applications for the next millennium.

Part Two is simply an alphabetical exploration of JDBC's classes and, more importantly, interfaces. Each class or interface is analyzed in detail, starting with an overview, followed by the complete class or interface definition, constructors, methods, and fields.

The book's two appendices are worth noting: Appendix A "For Driver Writers" contains a collection of important dos and don'ts when implementing a JDBC driver (which no other book covers). Appendix B "JDBC Design" gives a historical perspective on the design and evolution of JDBC. Here, for example, you'll find an explanation of why JDBC does not support scrollable cursors to navigate result sets forwards and backwards (JDBC only supports forward navigation).

Finally, inside the back cover is a very handy quick-reference card, which summarizes the classes, interfaces, and methods used in everyday JDBC programming by way of a short (half-page) code fragment. The remainder of the card contains tables relating to the mapping of SQL types to Java types, and vice versa.

Java Database Programming with JDBC (2nd ed.)

The back cover of

Java Database Programming with JDBC



ed.)" states that one of the book's authors, Karl Moss, was the software engineer who single-handedly developed the JDBC-ODBC bridge that comes bundled with the JDK these days. With such an author pedigree I had high expectations for this book. I was disappointed. The first three chapters, "JDBC Databases the Java Way," "SQL 101: An Introduction to SQL," and "Using JDBC Drivers" were weak. Chapter 4, "The Interactive SQL Query Applet," was extremely poor, containing stuff like "The applet structure has a well-defined flow, and is an event-driven development." I also found poor advice ("We use several global objects so that we don't have to pass around globally used objects...this approach also adds to the overall efficiency.") and plain old wrong statements (the entire paragraph on page 39).

When the first code listings start to appear, more disappointments lie in ambush: inconsistent identifier case, inconsistent layout, inconsistent use of indentation, confusing identifiers (for example, Con for a Connection, then Con again for a GridBagConstraints moments later!), and comments that follow the statements they refer to, going against the universal, unwritten style convention of comments preceding associated code.

Available from Computer Literacy

Chapter 5 "Middleware" continues the disappointing trend. After a brief but (admittedly) clear introduction to the pros and cons of three-tiered database application designs, the authors present an "application server" without any clear discussion of the server's design or even its implementation. Their ApplicationServer class relies on multithreading, inter-thread synchronization, and Java's networking API to do its thing, yet the reader is left to reverse engineer the rationale behind the code entirely on his own. The authors simply continue with "Now that we have the server code..." and commit the same pedagogical crimes with the client application (an applet) that's supposed to connect to the application server.

With Chapter 7 "Writing Database Drivers," the book delves into what is undoubtedly its true selling point: the design and implementation of JDBC drivers. The SimpleText JDBC driver uses, as its name implies, plain text files instead of a proper SQL database engine as a medium with which to build a DBMS (and an ultra-simplistic one at that). Not surprisingly, in view of Moss' experience, the book also contains an entire chapter (Chapter 8) on accessing ODBC services. Here, the code quality changes for the better, no doubt because it was written by author number two. Chapter 12 "The Multimedia JDBC Application: IconStore" and Chapter 13 "Working with Query Results" feature the book's largest example applications that rely on JDBC.

The last two text chapters, Chapter 14 "Server-Side Databases: Servlets and JDBC" and Chapter 15 "Building Data-Aware Components Using Java Beans," were no doubt added to this second edition to address these new JDK 1.1 features. Both chapters contain examples that show off the strengths of the respective APIs which, when combined with JDBC, really produce exciting, state-of-the-art cocktails able to solve real-world problems cheaply, quickly, and efficiently.

The API reference section of this book is very poor. It is too compact and, in places, even omits method descriptions (the whole list of DatabaseMetaData methods, for example) or simply cuts and pastes the same "generic" explanation (see page 337).

Finally, sandwiched between Appendix B and the index is a "Bonus Chapter," which is not mentioned in the table of contents. Taken verbatim from another Coriolis title (meaning that this chapter refers to other chapters you can't read), this "bonus" chapter explains the Java 1.1 Event Model. I can only wonder about the reasoning behind this publishing technique (page fill? advertising for the other book? recycling an explanation from another book?).

1 2 Page
Join the discussion
Be the first to comment on this article. Our Commenting Policies
See more