<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mission Data Blog &#187; as400</title>
	<atom:link href="http://www.missiondata.com/blog/tag/as400/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.missiondata.com/blog</link>
	<description>Louisville-based Web Development &#38; Software Engineering</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:58:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>iSeries SQL Performance</title>
		<link>http://www.missiondata.com/blog/system-administration/68/iseries-sql-performance/</link>
		<comments>http://www.missiondata.com/blog/system-administration/68/iseries-sql-performance/#comments</comments>
		<pubDate>Mon, 12 Mar 2007 01:08:10 +0000</pubDate>
		<dc:creator>Rich Rodriguez</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[as400]]></category>
		<category><![CDATA[IBM Visual Explain]]></category>
		<category><![CDATA[Utilities]]></category>

		<guid isPermaLink="false">http://www.missiondata.com/blog/utilities/68/iseries-sql-performance/</guid>
		<description><![CDATA[Our project has entered the stage where we start tuning the data access to improve performance. This project uses Hibernate to access a AS400/iSeries system via the JT400 JDBC driver. My prior experience using the SQL Server database introduced me to Microsoft&#8217;s Query Analyzer, which is a nice tool for identifying where you need to [...]]]></description>
			<content:encoded><![CDATA[<p>Our project has entered the stage where we start tuning the data access to improve performance. This project uses Hibernate to access a AS400/iSeries system via the JT400 JDBC driver.  My prior experience using the SQL Server<br />
database introduced me to Microsoft&#8217;s Query Analyzer, which is a nice tool for identifying where you need to index the database. A bit of searching turned up an IBM tool called <a title="Visual Explain" href="https://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzajq/rzajqmstvisexpl.htm">Visual Explain</a> that fits the same need. The sysadmin started the profiling tool against my connection, and I ran through a standard usage scenario in our application. Visual Explain showed each query, how long it took, the access strategy, and recommended indexes. This kind of tool is absolutely essential for database performance tuning.</p>
<p>The second important item we learned from this process is the performance difference between a true SQL index on the iSeries and a keyed logical index. From iSeries V4R2 on, SQL indexes have page sizes of 64k. By comparison, a DDS logical will max out at 32k, and will typically be much smaller. The performance is so much better that our customer is converting all all their DDS logical indexes to SQL, even if only their legacy RPG applications use it. <a title="DDS and SQL Performance" href="http://www-03.ibm.com/servers/eserver/iseries/db2/pdf/Performance_DDS_SQL.pdf">This IBM document</a> has a good discussion of this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/system-administration/68/iseries-sql-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>accessing as400 databases with Ruby, Java, and the RubyJavaBridge</title>
		<link>http://www.missiondata.com/blog/system-administration/46/accessing-as400-databases-with-ruby-java-and-the-rubyjavabridge/</link>
		<comments>http://www.missiondata.com/blog/system-administration/46/accessing-as400-databases-with-ruby-java-and-the-rubyjavabridge/#comments</comments>
		<pubDate>Tue, 25 Apr 2006 04:13:27 +0000</pubDate>
		<dc:creator>darrend</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[as400]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Systems Integration]]></category>

		<guid isPermaLink="false">http://blogs.missiondata.com/?p=46</guid>
		<description><![CDATA[iSeries systems and Ruby are separate universes right now; I know of no native Ruby way to connect to an AS400 system. However, with the help of Java we can bridge the gap. Probably the simplest example is connecting to an iSeries system using JDBC to select from some tables, and with the right libraries [...]]]></description>
			<content:encoded><![CDATA[<p>iSeries systems and Ruby are separate universes right now; I know of no native Ruby way to connect to an AS400 system. However, with the help of Java we can bridge the gap.</p>
<p>Probably the simplest example is connecting to an iSeries system using JDBC to select from some tables, and with the right libraries it is straightforward. It&#8217;s also fun to be doing some nifty quick Ruby but with some preexisting and proven Java libraries.</p>
<p>Also, if you use Java and Ruby, definitely put arton&#8217;s <a href="http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge">RubyJavaBridge</a> in your pocket; you&#8217;ll end up using it more than once.</p>
<p>What you&#8217;ll need:</p>
<ul>
<li>Ruby (well yea)
<li>Java (ok)
<li>access to an AS400 system (that&#8217;s the whole point here&#8230;)<br />For testing, I&#8217;ve been using a free account available from <a href="http://as400.holgerscherer.de/indexeng.html">Holger Scherer Software und Beratung</a>.
<li><tt>jt400.jar</tt> jdbc drivers from <a href="http://jt400.sourceforge.net/">JTOpen</a>, a great open-source Java library for AS400 access.
<li><a href="http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge">RubyJavaBridge</a> is the keystone for this.
</ul>
<p>Installing the software is the hardest part of this exercise, but it&#8217;s more tedium than anything. Once you&#8217;ve got it all downloaded and running the fun can begin.</p>
<p><span id="more-46"></span></p>
<pre>
<code>require 'rjb'
Rjb::load('jtopen_5_0/lib/jt400.jar',['-Djdbc.drivers=com.ibm.as400.access.AS400JDBCDriver'])

DriverManager = Rjb::import('java.sql.DriverManager')

begin
  connection = DriverManager.getConnection('jdbc:as400://as400.holgerscherer.de','YOUR_USERNAME','YOUR_PASSWORD')
  statement = connection.prepareStatement("SELECT count(*) FROM SYSIBM.TABLES")
  result_set = statement.executeQuery

  while(result_set.next())
    puts result_set.getObject(1).toString
  end
ensure
  result_set.close if defined?(result_set) &amp;&amp; !statement.nil?
  statement.close if defined?(statement) &amp;&amp; !statement.nil?
  connection.close if defined?(connection) &amp;&amp; !connection.nil?
end</code>
</pre>
<pre>
<code class="console">$ ruby as400_rjb.rb
19138</code>
</pre>
<p>Very readable, I think. Java and Ruby actually play well together given half the chance and <a href="http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge">arton&#8217;s fantastic bridge</a>.</p>
<p>Compare this with the pure Java implementation.</p>
<pre>
<code>import java.sql.*;

public class As400Jdbc
{
  public static void main(String args[])
  {
    Connection connection = null;
    try
    {
      connection = DriverManager.getConnection("jdbc:as400://as400.holgerscherer.de","USER","PASS");
      PreparedStatement statement = connection.prepareStatement("SELECT COUNT(*) FROM SYSIBM.TABLES");

      ResultSet resultSet = statement.executeQuery();

      while(resultSet.next())
      {
        System.out.println(resultSet.getObject(1));
      }
    }
    catch(SQLException e)
    {
      throw new RuntimeException(e);
    }
    finally
    {
      try{ if(connection!=null) connection.close(); }
      catch(SQLException e)
      {
        throw new RuntimeException(e);
      }
    }

  }
}</code>
</pre>
<pre>
<code class="console">$ javac As400Jdbc.java
$ java -cp jtopen_5_0/lib/jt400.jar:. -Djdbc.drivers=com.ibm.as400.access.AS400JDBCDriver As400Jdbc
19138</code>
</pre>
<p>The Ruby code and the Java code are nearly one-for-one so far, and that&#8217;s fine. Still, let&#8217;s see if we can&#8217;t pull the Java code more into Ruby&#8217;s world. The <code>begin...end</code> stuff gets tiresome; it would be nice if these Java classes could handle the resource allocation and disposal drudgery for us, using blocks.</p>
<pre>
<code>require 'rjb'
Rjb::load('/home/darren/dload/jtopen_5_0/lib/jt400.jar',['-Djdbc.drivers=com.ibm.as400.access.AS400JDBCDriver'])

DriverManager = Rjb::import('java.sql.DriverManager')
class &lt;&lt;DriverManager
  def with_connection(*args)
    begin
      connection = DriverManager.getConnection(*args)
      yield connection
    ensure
      connection.close
    end
  end
end

DriverManager.with_connection('jdbc:as400://as400.holgerscherer.de','USER_NAME','USER_PASS') do |conn|
  statement = conn.prepareStatement("SELECT count(*) FROM SYSIBM.TABLES")
  result_set = statement.executeQuery()
  result_set.next()
  puts result_set.getObject(1).toString
end</code>
</pre>
<p>I know I&#8217;m a geek because stuff like this makes me giggle. So many worlds are colliding here&#8211;Ruby, Java, AS400, DB2, the client system (Linux in this case)&#8211;and it all comes together so nicely. </p>
<p>I&#8217;m not saying I&#8217;d build an app out of this, but it will more than suffice for ad-hoc queries and quick scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.missiondata.com/blog/system-administration/46/accessing-as400-databases-with-ruby-java-and-the-rubyjavabridge/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

