Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@greghelton
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/7f52b1e210dedcfd11e5 to your computer and use it in GitHub Desktop.
Save greghelton/7f52b1e210dedcfd11e5 to your computer and use it in GitHub Desktop.
This is a Sinatra app displays the result set from an AS400 RPG program in a web page. The RPG program takes two character strings as input parameters and capitalizes them and returns them in a two field resultset. (Note: this code leaves the resultset, statement and connection in limbo). Execute this code by first starting the JRuby app then en…
require 'sinatra'
gem 'sinatra'
require 'sinatra/reloader' if development?
require 'jt400.jar'
require 'yaml'
set :public_folder, 'public'
db = YAML.load_file '/config/database.yml'
Java::JavaClass.for_name db['driver']
connection = java.sql.DriverManager.get_connection(db['dburl'], db['username'], db['password'])
get '/hello' do
"Hello Sinatra!"
end
get '/capitalize' do
a = params[:first]
b = params[:last]
statement = connection.prepare_call("{call GHELTON.SQLRPGJDBC(?,?)}")
statement.set_string(1, a)
statement.set_string(2, b)
results = statement.execute_query
results.next
"<br/>#{results.get_string(1)} <br/>#{results.get_string(2)}<br/>"
end
# A sample Gemfile
source "http://rubygems.org/"
gem 'sinatra'
gem 'rack'
gem 'sinatra-reloader'
The JDBC jar file and Yaml config are rerequisites for this project. For more detail see https://gist.github.com/greghelton/6735149b821ac17f0d3a
1. With JRuby installed, get Bundler
jruby -S gem install bundler
2. Create the gemfile
bundle init
3. update the Gemfile with the code from above
4.Install the gems
jruby -S bundle install
5. Create the JRuby program AS400webpage.rb with the code above
6. Execute the JRuby program
jruby AS400webpage.rb
7. Visit the web page of the Sinatra app
http://localhost:4567/capitalize?first=Greg&last=Helton
and the web page will produce the results of the AS400 stored procedure call
GREG
HELTON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment