19
Tue, Nov
1 New Articles

Practical SQL: DB2 at Home, Part 1, the Environment

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
 
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.

 

What's Involved

 

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 softwareDB2 in particularcan 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:

 

  1. Install VirtualBox
  2. Download DB2 10.1 VM from IBM and create a VM for it
  3. Install Guest Additions
  4. Map shared drive
  5. Install SQuirreL SQL client
  6. Copy JAR files from DB2 to SQuirreL
  7. 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.

 

The Result

 

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:

 

 

010715PlutaFigure1a

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 interfacefrom 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:

 

010715PlutaFigure2

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!

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: