HolubSQL:

An Embedded SQL Interpreter

Download HolubSQL.jar, version 1.0a, released 27 Sept, 2004.

If you have Java installed on your machine, you can "open" the file rather than saving it to the disk if all you want to do is run the console application.

HolubSQL.jar is an embedded SQL interpreter (with a JDBC wrapper), as described in my book Holub on Patterns. By "embedded," I mean that this is a set of classes that you incorporate into your program. There's no separate server, and all of the database tables are held in memory (until you flush them to disk explicitly). The database is quite suitable for small applications.

The .jar contains an executable version of a small "console" application that exercises the database, the .class files that comprise the database engine and JDBC layers, the source code presented in the book (with known bugs fixed), and javadoc documentation.

Execute the downloaded program with java -jar HolubSQL.jar. A popup will prompt you for the full path name of a directory to use as your database (tables are files in the directory), and then the console window will display itself. Type SQL into the top window and see the results in the bottom one.

You don't have to unpack the jar unless you want to look at the sources or documentation. You'll first be prompted for a directory to use as the database (tables are files within that directory). This directory must already exist when you launch the console. The console itself will then pop up. You can type SQL into the upper window, hit "Submit," and see the results in the lower window.

For the jdbc layer (and console application) to work, you must install the J2EE JDK to get the java.sql.* interfaces. You do not need to download or install Sun's application server, which is part of the all-in-one bundle.

To use the database classes in your own programs, just put the .jar file into your CLASSPATH environment. (After doing so, you can execute the console with java com.holub.database.jdbc.Console if you like.)

I've tested using both Java 1.4.2 and the Java 5 release candidate, the enclosed .class files are 1.4 files, so should run fine with either JVM. Note that the code will generate a few "deprecation" and "uses unchecked or unsafe operations" warnings with the 1.5 compiler. There is no way to eliminate these warnings and keep the code 1.4 compatible, so you may want to compile with the -nowarn or -source 1.4 flag.

The book contains a very detailed description of this implementation.

–Allen Holub

Get the code from my book by following the instructions at right.

SQL (Structured Query Language, usually pronounced SEE-QUILL) is the dominant database-access language. To understand the interpreter in the book, you'll need to know the basics.

Judith S. Bowman, Sandra L. Emerson, and Marcy Darnovsky's The Practical SQL Handbook is a great introduction to SQL. It covers just the language, so you should supplement it with at least one database-design book if you intend to do real database work. It's a great way to get up to speed quickly.

If you're in too much of a hurry to read a book. W3 School's SQL Tutorial is a terse, but good enough, introduction to the language. This is really a better reference than it is a textbook, but it will give you the basics.

Also good is SQLzoo's A Gentle Introduction to SQL.

When you program in Java, you have to send SQL to the database server using JDBC. Sun's JDBC Tutorial is a reasonably complete introduction to JDBC—Java's Database-Access library. This is probably the best way to come up to speed quickly on the basic library. The Console.java class in HolubSQL.jar uses JDBC to exercise the database.

Coming Attractions: In the near future, I'll augment this page with an extensive introductory-level article on formal grammars and recursive-decent parsers. Sign up for the newsletter if you'd like to be notified of changes to the web site.