DB2 is IBM's universal database, and that means you can learn about it at home without an IBM i!
One of the great features of the IBM midrange platform is its integrated database. For the longest time, we midrange programmers didn't even have a name for the database; we just knew how to access it with RPG and later with SQL. But as IBM targeted other platforms, they put everything under the umbrella name of DB2, the name of the mainframe DBMS. Today you can get DB2 on your home computer so that you can test the latest and greatest features at your leisure. It does, however, take some thought as to how you want to set it up, and this article gives you some input into that decision-making process.
Why Do This at All?
Native I/O, also known as Record-Level Access (RLA), is the overall term for the traditional keyed access CHAIN and WRITE operations we're used to in RPG, and it allowed direct access to the database in a way that could be easily written, but more importantly it was easy to analyze and debug the database logic. That direct access to the database was what made RPG such an incredibly powerful business language, and today many RPG programmers still use little or nothing besides native I/O. But over the years computing power has exploded, along with memory and disk speed. SQL optimization has progressed so much that many operations that simply weren't practical a decade ago are easier to design and sometimes even faster under SQL than under native I/O. Therefore, it's important for RPG programmers to become expert SQL programmers as well. Because of the differences in SQL syntaxes (despite the standardization of the language, differences exist), you can't really learn DB2 by playing with personal database engines like MySQL. For most of us, the only way to really learn DB2 is to have access to an IBM i (or an IBM mainframe!). I decided that it was time to figure out how to get DB2 running at home.
Basically, all SQL configurations consist of two things: a database server and a database client. And while each variant of SQL has its own native client, you can also find some really good generic clients, including some excellent free products. That was a primary focus: free everything! I wanted to install this entire configuration without spending a penny. Just as important, though, is a way to install this without affecting my environment. After doing some research, I decided to go virtualized for a couple of reasons: first, it allows me to run this entire environment without affecting my workstation configuration; second, there are already appliances (preconfigured virtual machines) with DB2 installed. That means I don't have to even learn how to install DB2…at least for now.
The only extra complexity from this decision is that, in addition to the server and client, I need a virtualization platform. I decided to use VirtualBox from Oracle. It's simple and easy to use. Not only that, but in my experience it works better with Linux: both running Linux and running on Linux. That's important to me because I have side projects that involve little boxes like the Intel NUC, and I like to run Linux on those and then run a virtual machine on Linux, and VirtualBox does that very well.
Remember, you don't have to run virtualization. You can simply install all the software on your machine. But I find that database software—DB2 in particular—can be very intrusive and can take over the settings of your machine. What I do instead is download a virtual machine image and run it on a hypervisor; then I don't have to worry about it being a little grabby. In fact, even if I completely trash the installation, I just delete the VM and start all over. So this is what I did:
- Install VirtualBox
- Download DB2 10.1 VM from IBM and create a VM for it
- Install Guest Additions
- Map shared drive
- Install SQuirreL SQL client
- Copy JAR files from DB2 to SQuirreL
- Configure SQuirreL SQL
Steps one and two would be all I needed if I intended to use only the native SQL utility, which in this case is IBM's Data Studio. I like Data Studio. It has some benefits because it understands DB2, and it's Eclipse-based, which makes it comfortable to use for those of us who use IBM's Rational tooling. On the other hand, a generic utility like SQuirreL SQL works with any SQL database, so as you become adept you can use it to access other databases in your environment. This can be important as you continue with your SQL journey.
So did I end up with a working environment? Yes, I did. I now have a virtualized environment that I can use to explore all of the intricacies of IBM DB2 10.1. I can back it up by simply copying a folder to a backup drive, and I can clone the entire environment with a couple of clicks. How does it work? Well, here's an example of the IBM Data Studio:
Figure 1: The IBM Data Studio looks like this.
If you've used any Eclipse-based tools, you'll be immediately familiar with the basics of the interface—from the multiple panes to the run and debug tools. You have your traditional explorer interface and the standard multi-tabbed windows. The SQL statement is nicely color-coded, and the results are displayed in a format that's easy to read. This is running inside the actual VirtualBox environment, hence the VirtualBox in the title bar. This can be a bit of a problem for some folks, as under load the GUI sometimes jitters a tiny bit, but after installing the Guest Additions (step three), the occurrence of such artifacts dropped to almost zero. I then executed steps four through seven to install SQuirreL SQL; here's what the interface looks like:
Figure 2: Here's a look at the SQuirreL SQL interface.
A couple of interesting points here. First, this is running on my desktop, not inside VirtualBox. In fact, it could be running anyplace in my network. As long as it knows the IP address of my virtual machine, SQuirreL SQL can access the SQL engine and run my commands. Second, you may notice that it's not entirely comfortable with the "fetch first 3 rows" syntax. That syntax is entirely specific to DB2, so SQuirreL SQL doesn't understand it. The request will get sent to the engine and the results will be interpreted correctly, but the statement won't be validated. That's the tradeoff with a generic client.
So, welcome to the new desktop DB2 environment. I hope to continue using this environment to test various DB2 techniques and provide you with as much knowledge as possible. Remember, too, that IBM provides features in this version of DB2 before they get to us on our beloved midrange, so you're not only learning today's techniques, but also positioning yourself for tomorrow as well. Enjoy!