|Latest 7 Posts
| Open Source Contribution|
Fri, Jun 16th 2017 7
| Docker Quick Tips|
Fri, Apr 28th 2017 2
| Notes in 9: Dev Tools Grab Bg|
Tue, Apr 4th 2017 1
| Custom JSON Serialization With GSON|
Mon, Jan 23rd 2017 2
| Recapping 2016|
Mon, Jan 16th 2017 5
| Rebirth: An App of Ice and Fire|
Wed, Dec 14th 2016 5
| Scripting Server Upgrades|
Fri, Nov 11th 2016 4
| Building Java Objects From JSON|
Thu, Jan 22nd 2015 13
| Open Source Contribution|
Fri, Jun 16th 2017 7
| REST is Best|
Wed, Sep 17th 2014 6
| Server REST Consumption with Authentication|
Mon, Aug 18th 2014 6
| Site Anchors|
Wed, Jun 1st 2016 6
| Git History Searching|
Tue, Jul 12th 2016 6
| Consistent Multi-Value Formatting|
Tue, Aug 12th 2014 5
| Alternate Front-End Development|
Tue, Jul 14th 2015 5
Tue, Oct 6th 2015 5
| SCM Survey Results|
Tue, Apr 12th 2016 5
||Using Node to Connect to an IBM i
This article is Part 2 in a 2-Part Series.
I’m back, this time with a spin on the base application I established in the last post. This flavor of things will utilize JDBC to connect to a DB2 table on an IBM i. This should work with anything the
jt400.jar can connect to, and should you swap out the
lib/jt400.jar for any other JDBC jar (PostgreSQL, Oracle, MySQL, etc.), the only changes you would need to make are to ensure your SQL queries/statements are valid for the data source.
As I break down the specifics for each implementation, you will find that I’m focusing on changing only a couple of files, the js files for the
config module and for the
util module are the biggest, with mere implementation concerns in the available
I recently stumbled across a long forgotten Facebook message (in the category of Facebook thought I didn’t want to see it) regarding a comment I had made on a developerWorks article, stemming from a micro-service I had written, to stand up a Node instance so I could consume data from our IBM i (iSeries/AS400/a power system by any other name) in a more RESTful/REST-like JSON API capacity.
The funny thing about the developerWorks article was that it eventually was refactored/updated to get around a dependency of a data server driver, which apparently is freely available for DB2 on other platforms than the IBM i (the strange things I had to learn at the time). In the end, I switched to using a jdbc package from npm, specifically the one titled ‘jdbc’ (at version 0.0.15), which subsequently underwent significant changes in their API format, meaning that I’m going to show a version with updated specifics using the ‘jdbc-pro’ package from npm.
The unique dependencies here are:
jt400.jar (which my
.gitignore is set to ignore
.jar files, so you’ll need to download and include your own copy of it; I’ m parking mine at the path of
- the npm package
jdbc-pro (which makes its main jdbc module accessible via a
require('jdbc') statement); install via
npm i -S jdbc-pro
Part of why you’ll need to download and include your own copy is, while I know the project to be open sourced from IBM under the IBM Public License 1.0, I’m just not familiar with that license. For those looking for one, the tldr legal page for IBMPL does a good job summarizing the conditions of the license.
Specifics With IBM i and JT400
The core connection component here is the
jt400.jar allowing for a JDBC connection. When I first implemented my initial version, I tried using the
jt400 package, which I ended up not using in favor of the
jdbc package due to some issues and preferences. Currently, the
jdbc package I used has moved on to a newer, major breaking API change, which I haven’t used, so the following will make use of the
jdbc-pro package from npm, which looks to be the one I would choose should I start it again, today (and is more consistent with my previous implementation).
Data Connection Config
For the config of connection, we’ll want to establish the url to the IBM i, the path to the
lib/jt400.jar, driver name (provided), and a valid user name and password. This is exported as an object, making it directly usable in the data handling (
util) module, it’s been pulled in via a
require statement. You can see that I’m again using a number of environment variables to assign things like the url property, or username or password. My example has fail-over values, but it’s best to keep those separate from the code base.
Next, I defined a common connection closing function, then two functions for the actual SQL statement handling; that’s because this package has two separate methods. One is for queries (e.g.-
SELECT * FROM ...) and one for updates (either
INSERT operations); per the npm package documentation.
I wrapped up those functions using a common function for both initializing a connection and for closing the jdbc connection. You’ll note that I’m approaching callback hell, but I’ve deliberately avoided this as much as possible by separating out my functions to invoke the passed callback functions and handle any potential errors generated. This can seem tedious, but when it comes to event driven operations, it’s best to write code that matches the async nature.
Lastly, I export those two primary functions as a JS object (as methods) to be called via their require statement in my
Now that my connections are configured and my data handling is provisioned, all I need to do is invoke it in my various
routes. As you can see from my data
util module, the exposed
query method is simple enough to use:
require the module
- call the
- passing in the SQL query and
- a function, which has two parameters, error or data
This way, if the error handle is null, it will not execute the error block, and vice versa. At this point, I hope the up-front modularizing is starting to show off its utility, as the implementation is about as simple as you can get.
The other available
routes all get updated as well, but they’re virtually identical, save for the specifics of the SQL query.
You can find my source code for this version of the project, in full, in the same GitHub repository as last time, just in the
As you can see, once we’ve configured and provisioned our connection, we can use it pretty easily. While wrapping up a bunch of queries to an RDBMS via JDBC can seem a bit silly, I have to say that the performance benchmarks I did at the time were quite impressive and the micro-service had the great benefit of being easily maintained outside my main production application, either by myself or another developer (who helped in setting up the SQL queries, due to their more intimate knowledge of the DB2 tables).
You can probably guess what’s coming up with the next post in this series. Once we connect, in a well structured way, to any data source, any data source becomes swappable by configuration. So tune in next time for an early, expanded example of the use and implementation of the domino-nsf package for access to a Notes/Domino file.
Apr 20, 2016
| Recent Blog Posts
Open Source Contribution|
Fri, Jun 16th 2017 5:00p Eric McCormick
Intro It’s time to clear some of the backlog. I started this post a few months back and it should probably be sent on its way to clear the pile of drafts I haven’t finished yet… 🤔 I have a bit of a passion for open source software. My preferred distribution of Linux has been Ubuntu since 4.10, the Warty Warthog (I was even a minor contributor on a short lived, wildly popular project that aimed at improving the Ubuntu experience early on), I’ve enjoyed most open source projects I’ve
Docker Quick Tips|
Fri, Apr 28th 2017 3:00p Eric McCormick
Docker If you have been living under a rock, Docker is pretty much amazing. If you haven’t been living under a rock, you may be getting used to the idea of Docker, but still have the occasional question. I’ve found myself using Docker in increasing amounts and complexity over the last year or so. I’ve recently decided to start recording some of the tasks I’ve found useful, some of which may be less familiar to a beginner. If you’re so inclined, check out the playlist, embedded here.
Notes in 9: Dev Tools Grab Bg|
Tue, Apr 4th 2017 1:00p Eric McCormick
Intro I’m on Notes in 9 again, with a “grab bag” of a couple of tools I’ve put together recently that may be of a varying degree of useful for other Domino + XPages developers. You don’t need these to do development, but for the right person, they may help with their development workflow. Also of note, with the upgrade to Swiper with the FP8 release of Notes + Domino Designer, the limitations previously mentioned are no longer there! This means that my second tool I talked about, node-
Custom JSON Serialization With GSON|
Mon, Jan 23rd 2017 2:00p Eric McCormick
Mon, Jan 16th 2017 3:00p Eric McCormick
Per usual, I’ve had a little break between things and decided to catch up with a bit of a summary of some recent things that each didn’t necessitate their own post.
2017 IBM Champion
For starters, I’m honored to be named an IBM Champion in Collaboration Solutions (/ Social Business) for the third time. This would be a hat trick in (ice) hockey 🏒. I’m happy to be recognized with a group of people, developers and more, who are passionate about both their work and the plat
Rebirth: An App of Ice and Fire|
Wed, Dec 14th 2016 4:00p Eric McCormick
If you read my blog for any of the Saga of Servlets series, then I hope that you’re excited I’m returning to the application I put together for it. This time, it’s as a conversation piece in regards to some of the build process modernization I engaged in recently, in order to unify the code base in its git repository. In any case, it’s helping pave the way forward before I update some of the back-end elements, when it will again be a talking point for some additional rework and
Scripting Server Upgrades|
Fri, Nov 11th 2016 2:00p Eric McCormick
This one might be slight departure from my usual, but those that have followed my blogging this past year will have noticed a bit more of a leaning towards DevOps in some of my posts. This echoes a lot of what I’ve been concluding as increasingly a necessary part of development; that we need to consider a picture large enough to encompass the themes surrounding development functions and, like any good developer (DRY ~= “lazy”), automate the heck out of it.
I had p
Everything Old is New Again|
Mon, Oct 24th 2016 8:00p Eric McCormick
Every so often, it’s good to reassess one’s position. This is good from both a standpoint of being inquisitive and even interrogative, but when it comes to the ever changing landscape of the front-end development space, it’s not only inevitable, but must be embraced for what feels the need to “stay afloat”. I’m changing theme of my blog, hopefully for the better. The previous theme was good and did a great job of getting things started, but while I had forked a copy of a good
Thu, Oct 20th 2016 8:00a Eric McCormick
If you’re just here to learn a little about how to “squash” commits with git, skip down a ways. Otherwise, hold on, and I will catch you up on a couple of personal notes before we get there.
On the Blog
It’s been a little while since I blogged last. This has been due to a combination of reasons; specifically, I’ve been busy with:
my family, it was the end of summer with lots of things going on
a number of projects around the house (a deck removal and basement remodel
Wed, Aug 24th 2016 8:37a Eric McCormick
MWLUG was a great success as far as I’m concerned. Each time I’ve gone I’ve had the great enjoyment of being able to attend some high quality sessions, meet with lots of colleagues and friends from the community, and get a view into products and solutions many people are undertaking, over conversations and interactions outside of the sessions. This is always a great way of interacting with others who were able to make it. Unlike the IBM conference of Connect(EDsphere), this is purel