Chapter 4. Deploying applications with DB2 183
4.5.3 Creating a sample Ruby application
In order to demonstrate Ruby application deployment, we have a sample
application named itso_rubyapp.rb that reads the connectivity information from
the command line and establishes connection to a database. The database can
be both local or remote. If the connection fails, the application returns an error
message. The complete code is shown in A.3, “Ruby” on page 263 and is
available for download. For the download instructions, refer to AppendixB,
“Additional material” on page267.
To run the application, create a directory and then save the application as
itso_rubyapp.rb. You can run the application as in Example4-25. demonstrating
a successful connection to a remote database with uncatalog connection.
Example 4-25 Successful connection using itso_rubyapp.rb
itsouser@ubuntu:~/redbook$ ruby itso_rubyapp.rb mensa 50001 test db2inst1
password
Trying to establish connection...
Is connection active? : true
Closing connection...
Connection closed.
If there is any incorrect information, the connection will fail and an error message
will be thrown as shown in Example 4-26.
Example 4-26 Failed connection using itso_rubyapp.rb
itsouser@ubuntu:~/redbook$ ruby itso_rubyapp.rb mensa 50001 test db2inst1
wrongpassword
Trying to establish connection...
[IBM][CLI Driver] SQL30082N Security processing failed with reason "24"
("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001 SQLCODE=-30082
4.5.4 Deploying a Ruby application with the DB2 drivers
In this section, we demonstrate how to deploy a DB2 Ruby application with the
DB2 drivers. We assume that the target system already have the Ruby and Rails
framework installed but DB2 components are not installed on the system. The
general tasks for deploying a Ruby application with ODBC and CLI driver are:
򐂰Prepare IBM_DB2 gem file and redistributable DB2 ODBC and CLI driver files
򐂰Prepare the Ruby application package
򐂰Prepare the deployment package
򐂰Deploy the deployment package to the target system
We organize all the deployment files under a directory, ruby_deploy.