This is the second episode of the article JTOpen for .Net environment in which we have learnt to create the .Net libraries for being able to work on our IBM i system from Windows in C# (or VisualBasic.NET)
In the folder ...\ikvm-7.2.4630.5\bin\ we find all the dlls which will allow us to use Java within a VisualStudio project, while, with this command run on our PC:
.\ikvm-7.2.4630.5\bin\ikvmc.exe -target:library \JTOpen\jtopen_10_6\lib\jt400.jar
We also have obtained the jt400.dll which will allow us to have full control of our IBM i system, including the chance to connect quickly.
using System; using com.ibm.as400.access; using java.sql;
Connection db2conn = null; AS400JDBCConnection db2connJT = null; DriverManager.registerDriver(new AS400JDBCDriver()); db2conn = DriverManager.getConnection("jdbc:as400://penelope;queryTimeout=0;translate binary=true;date format=iso;time format=iso",, ); db2connJT = (AS400JDBCConnection)db2conn;
try { String query = @"SELECT REPLACE(cast(current_date as char(10)),'-',''),REPLACE(cast(current_time as char(8)),'.','') FROM sysibm.sysdummy1"; ResultSet rst = db2connJT.createStatement().executeQuery(query); ResultSetMetaData rsmd = rst.getMetaData(); while (rst.next()) { for (int i = 1; i <= rsmd.getColumnCount(); i++) { Console.WriteLine(rsmd.getColumnName(i) + " " + rst.getString(i)); } Console.WriteLine("-----------------------------------------------------------"); } } catch (ThreadAbortException abortException) { Console.WriteLine((string)abortException.ExceptionState); db2connJT.close(); }
db2connJT.close();