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?).

SQL Database Programming with Java

In the author's words, "This book focuses on using SQL with Java and JDBC." Yet despite its primary focus on SQL, the book's coverage of application programmer-level JDBC is nothing short of excellent. In my opinion, definitely better than any other JDBC book reviewed this month! Its introductory chapters, "Introduction to Database Programming and Client-Server Systems" and "Relational Database Basics," were crystal clear, unlike most of the similarly named introductory chapters in

SQL Database Programming with Java

's competitors.

Available from Computer Literacy

McCarty, unlike the majority of technical book authors these days, is a very solid writer. His writing flows, his explanations are clear and accurate, the presented material is logically organized, difficult terms or concepts are not left without satisfying explanations, his code examples are highly readable, and so on. Because an unacceptable number of Java books suffer in quality these days, I urge authors of Java books past, present, and future to get a copy of Bill's book, to see that book writing is more than hopping on some publisher's mass-production conveyor belt and throwing together something that, at first sight, looks like a book.

OK, enough moaning, let's get back to talking about the book. The JDBC API itself is explored in detail in only one chapter, Chapter 5, but it is written so clearly and contains so many value-for-money examples that the reader is able to tackle any JDBC project upon completion.

Roughly halfway through the book is Chapter 8 "Designing Databases." Although this chapter isn't about JDBC or SQL, I mention it only because it is one of the best chapters on this topic that I've ever read. The remainder of the book continues its exploration of SQL, always by way of JDBC examples to illustrate new concepts or techniques. Clearly, the author knows his stuff, so SQL Database Programming with Java is not only a good read but also a "safe" read ("unsafe reads" are littered with errors).

One word of warning, though: The author uses Microsoft's Access database product as its database server. Some of the more advanced examples even require Microsoft's SQL Server. The former is probably not a problem for the majority of you, the latter could be.

Teach Yourself Database Programming with JDBC in 21 Days by Ashton Hobbs (SAMS Net)

The back flap of this title states that its intended audience fits somewhere within the "New-Casual-Advanced spectrum" of reader profiles (how any book can cater to both novice and advanced users, I will never understand). I think the beginners among you are in for a shock.

Teach Yourself Database Programming with JDBC in 21 Days

starts off in 5


gear. On page 5, I found sentences like "...you can execute normal SQL statements, dynamic SQL statements, and stored procedures that take both IN and OUT parameters." Without any


explanations for the terms and concepts used in this sentence, or a life saving glossary hiding in the back of the book, the "New-Casual" readers are left behind from the word "Go."

Available from Computer Literacy

By Chapter 2, "Database Concepts," the confusing writing style and poor organization come out in full force: After presenting a most muddled explanation of a database table, the author tries to explain what a primary key is.Then he writes, "Figure 2.1 displays how you can create a primary key column using SQL Anywhere's SQLCentral utility." (This book's vendor-bias rests on Sybase's SQL Anywhere and Symantec's dbAnywhere products.) Figure 2.1 is the first screenshot of the book, leaving the steps for creating (or opening) a database and creating (or editing) a table to the reader's imagination. Two sentences further, the author continues "Here, select the column EmpId and add it to the primary key." The EmpId column? Where does this column come from? Which table are we talking about here? Which database? And would it be too much to ask to tell the reader where this database is to be found?! Maybe a better title for this book would be "Teach Yourself Detective Skills."

The remaining chapters contain numerous and egregious problems:

  • Forward references (remember: no glossary to help you out).
  • Illogical ordering of material.
  • Factual errors ("Driver.jdbcCompliant() returns Boolean").
  • Material in one chapter repeated from, or overlapping with, that of a previous chapter.
  • Incorrect use of standard OOP terminology (the author refers to classes as objects all the time).
  • Poor writing style (For example, "You also learn how to create the splash window that the window will use.")

And if this list is not reason enough to leave Teach Yourself Database Programming with JDBC in 21 Days on the bookstore shelf, I'll give you one more reason: the featured application (Chapters 15 through 20). Chapter 15, "Creating the Knowledge Base Application GUI," introduces the author's "knowledge base" application. To set the scene for the project, the author completely omits any discussion of:

  • The database structure (schema) at the heart of the application.
  • The client-server architecture around which the application is structured.
  • Any inter-class or inter-object relationships.
  • The GUI to be created.

And so on. No requirements spec, no analysis, no design. You'd better not teach yourself this approach to software development if you like your job (or your pay checks).

JDBC Developer's Resource: Database Programming on the Internet

Interestingly enough, I received this book in two different spine sizes: 28 mm (1 inch) and a whopping 53 mm (2 inches). Both books have identical content, but their self-advertising impact in shops couldn't be more different. It just goes to show that book size (especially the spine) is more a result of unethical marketing than any other factor.

Ignoring outward appearances, this book is split evenly into tutorial and reference halves. The book starts off with a superfluous Java language primer followed by a relational database primer. Both try to summarize large and multi-faceted topics, and fail. Chapter 3, "JDBC Application Programmer Interface (API)," delves into JDBC proper by showing the standard sequence of events needed to access a database and perform some query on it (obtain a driver, make a connection, execute an SQL statement, process the result set). It's here that you first see one of this book's serious problems: All listings are typeset in a myopic double-spaced format, resulting in a book-wrecking 24 lines per page. At this ultra-low density, what should be half the fun of reading any computer book (reading the listings) becomes purely masochistic.

Available from Computer Literacy

The text that accompanies the first JDBC example also lacks in its pedagogical approach. In reference to the following code fragment

try { // load the JDBC driver Class.forName("jdbc.odbc.JdbcOdbcDriver");

the author writes "In this code fragment, a database driver is first loaded using the Class.forName method. This loads the JDBC-ODBC bridge driver and returns a reference to a Class object (which is ignored in this code)." How does a Class.forName load and install a JDBC driver for subsequent use if you throw away the reference to the Driver? Second, java.lang.Class existed long before JDBC was ever thought of, so how come Class is instrumental in making a JDBC driver available at runtime? The author doesn't explain this, which is a shame as it will confuse every alert newcomer to JDBC. (The simple answer, by the way, is that Class doesn't know anything about JDBC, but the JDBC driver itself always contains a static code block [static { … }] which takes care of registering the driver with the JDBC sub-system via JDBC's pivotal DriverManager class.)

If omitting explanations of some core JDBC mechanisms manages to confuse, then making factually incorrect statements must surely send the reader down a blind alley altogether: Some paragraphs later, the author writes "When instantiated, the DriverManager object uses...." Freeze frame! DriverManager never gets instantiated, so it is never an object. DriverManager is also called an interface in the reference section of the book (which it is not, it's a class packed with concrete, static methods). When Java authors get their knickers in a twist with such basic terms as "class," "object," and "interface," then I prefer to put the book back on the shelf and give another a chance. Before I do so with this particular title, I feel obliged to note that there may be one reason why you should give this book a try: It is one of the few JDBC books that presents a three-tiered application example (a "price guide" system).

And the winners are.... <silence in the audience please>

Purchase these books from

Computer Literacy

Database Programming with JDBC and Java, by George Reese

(O'Reilly) - ISBN: 1565922700

Java Database Programming, by Brian Jepson

(Wiley) - ISBN: 0471165182

JDBC Database Access with Java: A Tutorial and Annotated Reference, by Graham Hamilton, Rick Catell, and Maydene Fisher

(Addison-Wesley) - ISBN: 0201309955

Java Database Programming with JDBC (2nd ed), by Pratik Patel and Karl Moss

(Coriolis) - ISBN: 1576101592

SQL Database Programming with Java, by Bill McCarty

(Coriolis) - ISBN: 1576101762

Teach Yourself Database Programming with JDBC in 21 Days, by Ashton Hobbs

(SAMS Net) - ISBN: 1575211238

JDBC Developer's Resource: Database Programming on the Internet, by Art Taylor

(Prentice-Hall) - ISBN: 0138423520

Your needs as a future JDBC guru dictate which book(s) you will choose. My opinion is that all JDBC programmers, whatever their specific needs, should have official JDBC reference material close at hand. I'm a fan of the free-but-functional online javadoc files, but if you prefer books, then you will need Addison-Wesley's JDBC Database Access with Java: A Tutorial and Annotated Reference. This same title will also satisfy anyone needing a JDBC tutorial.

McCarty's SQL Database Programming with Java is the only other book that contains a well-written JDBC tutorial. In addition, if your SQL is rusty (or you're new to it), then you need this book pronto.

If you need to write your own JDBC driver(s), Brian Jepson's Java Database Programming and Patel and Moss' Java Database Programming with JDBC (2nd ed) are your only options. Go down to your local book store and compare the two to see which one agrees with you best (both are poorly written).

For those who drink their Java black and unsweetened, George Reese's Database Programming with JDBC and Java contains advanced and very valuable material on three-tiered application design and implementation, but remember, this book suffers greatly from its terseness.

If database programming isn't your cup of coffee, then stick around for next month when I'll review a stack of books that will surely appeal to a wider Java audience, focusing on algorithms and data structures.

Laurence Vanhelsuwé is an independent software engineer. Self-taught, he dropped out of college and immediately started a professional career writing arcade games. He has worked on such diverse technologies as X.25 WAN routers, virtual reality flight simulation, Postscript, and real-time digitized video-based traffic analysis.

Learn more about this topic

  • JavaSoft's official JDBC FAQ http://java.sun.com/products/jdbc/jdbc-frequent.html
  • JavaSoft's list of available JDBC drivers http://java.sun.com/products/jdbc/jdbc.drivers.html
  • JavaSoft's list of companies that support JDBC http://java.sun.com/products/jdbc/jdbc.vendors.html
  • A white paper on how to choose a JDBC driver http://www.weblogic.com/whitepapers/jdbc.html
Join the discussion
Be the first to comment on this article. Our Commenting Policies