{"id":2727,"date":"2013-04-16T11:38:53","date_gmt":"2013-04-16T16:38:53","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2727"},"modified":"2013-04-16T12:51:21","modified_gmt":"2013-04-16T17:51:21","slug":"query-as400iseries-from-jdbc","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/04\/16\/query-as400iseries-from-jdbc\/","title":{"rendered":"Query AS400\/iSeries from JDBC"},"content":{"rendered":"<p>We are migrating an in house system from the AS400 to Oracle, and I needed to look at the data in its &#8220;raw&#8221; format to assist with a migration plan.  I ended up using JDBC rather than the GUI provided by IBM.  I have always found this investment to be worth my time.  It eventually leads to reuse to perhaps do the actual migration, after the data has been mapped.<\/p>\n<p>What I found is that it is fairly easy to get connected, but the terminology differs.  For example, I assumed that TABLE_OWNER in the system catalog would be the schema to use to qualify the owner of a given table.  As you can probably tell, this is not necessarily correct.  In my case, I ended up querying the systables view in the catalog, and found a column named table_schema.  The value in this column for the table of interest is, of course, the correct name to qualify the table.<\/p>\n<p>Below is the soup to nuts simple class, just to get started.<\/p>\n<pre lang=\"java\" line=\"1\">\r\nimport java.sql.*;\r\n\r\npublic class db2RMSTables {\r\n  public static void main (String args[]) {\r\n    try {\r\n      Class.forName(\"com.ibm.as400.access.AS400JDBCDriver\");\r\n      System.out.println(\"getting connection...\");\r\n      Connection c = DriverManager.getConnection(\"jdbc:as400:\/\/hostname:port;naming=system;errors=full\",\"username\",\"password\");\r\n      System.out.println(\"got connection!!!\");\r\n      DatabaseMetaData m = c.getMetaData();\r\n      ResultSet tables = m.getTables(null, null, null, null);\r\n      ResultSet rst = c.createStatement().executeQuery(\"select * from EXPDEVD\/\\\"MRCHCAT\\\"\");\r\n      ResultSetMetaData rsmd = rst.getMetaData();\r\n      while (rst.next()) {\r\n        for (int i = 1; i <= rsmd.getColumnCount(); i++) {\r\n          System.out.println(rsmd.getColumnName(i) + \" \" + rst.getString(i));\r\n        }\r\n        System.out.println(\"-----------------------------------------------------------\");\r\n      }\r\n\r\n    }\r\n    catch (Exception e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>For the sake of completeness, I used the JTOpen driver.  I simply placed the jt400.jar file in my CLASSPATH, and all was good with the world.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are migrating an in house system from the AS400 to Oracle, and I needed to look at the data in its &#8220;raw&#8221; format to assist with a migration plan. I ended up using JDBC rather than the GUI provided&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/04\/16\/query-as400iseries-from-jdbc\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,42,24,25],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2727"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2727"}],"version-history":[{"count":8,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2727\/revisions"}],"predecessor-version":[{"id":2736,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2727\/revisions\/2736"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2727"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}