ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

from java to AS400

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • from java to AS400

    Dear All,
    Thanks for your help for ma questions in this forum.i really apreciate it thank you

    i have a problem from connecting from java to AS400......
    i want to be able to read from a physical file
    this is ma code below and where should i put the file jt400.jar in which directory?

    Thanks in advance for all your help










    HTML Code:
    try 
    {
                Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
            System.out.println("After Driver");
    } 
    catch (ClassNotFoundException e)
    {
               System.out.println("Database Driver could not be loaded " + e);
    }
            
      Define connection information.
      String databaseURL = "jdbc:odbc:Equation";
      String query;
    
      String userName = "user1";
      String password = "P13";
      Connection con = null;
    
     ResultSet resultSet = null;
     PreparedStatement ps = null;
    
    
    System.out.println("After Connection");
    
    query = "select * from library1/File1 where fieldone='0001';
    try 
       {
       ps = con.prepareStatement(query);
       resultSet = ps.executeQuery();
       resultSet.next();
       while ( !(resultSet == null))
          {
               System.out.println("field4 " + resultSet.getString("FIELD4"));
        resultSet.next();
    
        }
    
     System.out.println("Out");
       } catch (SQLException ex)
             {
             System.out.println("Global isFI failed to connect " + ex);
             }
    
    
     System.out.println("Finish");

  • #2
    Re: from java to AS400

    Hey Casparov,
    are you using Websphere as your IDE?

    If so, then your jt400.jar would be included under the Java Resources folder of your Dynamic Web Project...
    Last edited by bryce4president; November 15, 2007, 07:40 AM.
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: from java to AS400

      I have this in a separate jsp file that gets compiled in. I include this jsp in all my other jsp's.


      PHP Code:
      <%@page import="java.sql.*"%>
      <%@
      page import="java.lang.Object"%>
      <%@
      page import="java.text.*" %>
      <%@
      page import="java.util.Date" %>
      <%@
      page import="java.util.*" %>
      <%

          
      String url            "mydomain";
          
      String libraryName    "BPCSFFG, BPCSUSRFFG, BPCSUSRMM";
          
      String userName        "iSeriesLogon";
          
      String password        "MyPassword";
          
      String pgmid        "ProgramId    ";
          
      String ErrMsg "";


          
      Connection opnConn    opnAS400Conn(urllibraryNameuserNamepassword);

       
      %>
      <%!
      //--------------------------------------------------------------------------------------------------------------------------//
      //- Open an AS400 database connection
      //--------------------------------------------------------------------------------------------------------------------------//

           
      public java.sql.Connection opnAS400Conn(String urlString libraryNameString userNameString passwordthrows Exception {

          
      java.sql.Connection cn null;

        
      // Register the driver
          
      Class.forName("com.ibm.as400.access.AS400JDBCDriver");

        
      //  Create the database connection
          
      cn DriverManager.getConnection(
               
      "jdbc:as400:" url "; translate binary=true; naming=system; " +
               
      "extended metadata=true;libraries=" libraryName "; date format=iso",
               
      userName,
               
      password);

        
      // Return the connection object
          
      return cn;
        }


      %>
      <%!
      //--------------------------------------------------------------------------------------------------------------------------//
      //- Return an AS400 ResultSet
      //--------------------------------------------------------------------------------------------------------------------------//

          
      public ResultSet opnAS400Rs(java.sql.Connection cnString myQuerythrows Exception {

               
      java.sql.Statement stm =
                
      cn.createStatement(
                
      ResultSet.TYPE_SCROLL_INSENSITIVE,
                
      ResultSet.CONCUR_UPDATABLE);

               
      java.sql.ResultSet rs stm.executeQuery(myQuery);

               return 
      rs;
        }

      %> 

      Then in your java code you can do this call...

      ResultSet rs = opnAS400Rs(opnConn, SQLStatmentInAString);

      That is how I communicate back and forth, hope this helps.
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment


      • #4
        Re: from java to AS400

        thank you but am not using wepshere where than i can put the jt400.jar
        i re-made a small program to be able to make a connection from java to AS400 and retrieve a field from a physical file

        i place the jt400.jat under the lib folder of java
        but in compilation am getting an error
        package com.ibm.as400.access.* does not exist
        any idea wut else i should do?


        HTML Code:
        import java.sql.*;
        import com.ibm.as400.access.*;
        
        public class testAS400JDBC
        {
        //  public testAS400JDBC(){
        //  }
        
          public static void main(String[] args){
            // define login info for as400
            String host = "10.39.11.2";
            String user = "uiser";
            String pwd = "sdsd";
         
            try{
              // make sure driver exists
              Class.forName("com.ibm.as400.access.AS400JDBCDriver");
            }
        	catch(Exception e){
                System.out.println(e.toString());
            }
        
        //    try{
              // create a new connection from driver
        //      Connection con = DriverManager.getConnection("jdbc:as400://" + host, user, pwd);
        //      // create new statement from connection
        //      java.sql.Statement stmt = con.createStatement();
        
              // sql
        //      String sql="SELECT NAME FROM lib1.TEST01PF FETCH FIRST 4 ROWS ONLY";
        
              // execute query
        //      ResultSet rs = stmt.executeQuery(sql);  
        
              // loop through results
        //      while(rs.next()){
        //        System.out.println(rs.getString(1));
        //      }
         
              // close connection
        //      con.close();
              
        //    }
        //      catch(Exception e)
        //     {
        //      System.out.println(e.toString());
            }
          }



        thanks for your help again

        Comment


        • #5
          Re: from java to AS400

          I don't want to sound condescending but I have to ask this...

          have you checked to make sure that it does exist??
          Your future President
          Bryce

          ---------------------------------------------
          http://www.bravobryce.com

          Comment


          • #6
            Re: from java to AS400

            Just for reference when I'm searching, what version of Websphere App Server are you running?
            Your future President
            Bryce

            ---------------------------------------------
            http://www.bravobryce.com

            Comment


            • #7
              Re: from java to AS400

              am not using websphere am writing my orogram in a note pad and save it in the bin folder of the java folder
              and i compile it in command prompt in javac command

              Comment


              • #8
                Re: from java to AS400

                So you don't have an application server running on the iSeries?


                I have never tried it the way you are trying. I don't think I'm going to be of any help. Maybe someone else on here has tried this....I'll keep looking around though, maybe I can dig something up...
                Last edited by bryce4president; November 15, 2007, 08:37 AM.
                Your future President
                Bryce

                ---------------------------------------------
                http://www.bravobryce.com

                Comment


                • #9
                  Re: from java to AS400

                  thank you bryce4president

                  Comment


                  • #10
                    Re: from java to AS400

                    Look here towards the end. It has some stuff about making sure your PATH and CLASSPATH are set up correctly.... this might be your issue...it sounds to me like your javac can't fine your jars

                    http://www.itjungle.com/mpo/mpo021402-story04.htmlhttp://www.itjungle.com/mpo/mpo021402-story04.html
                    Your future President
                    Bryce

                    ---------------------------------------------
                    http://www.bravobryce.com

                    Comment


                    • #11
                      Re: from java to AS400

                      And this is full of stuff right from the horse's mouth. I didn't go searching through it, but I'm sure there is some stuff in there you can use...

                      http://www-03.ibm.com/servers/enable...ployguide.html
                      Your future President
                      Bryce

                      ---------------------------------------------
                      http://www.bravobryce.com

                      Comment


                      • #12
                        Re: from java to AS400

                        You need to add any jar's that your app depends on to the classpath. I have never used WebSphere but I have used Eclipse quite a bit and WebSphere is built on eclipse. Eclipse makes it nice and easy to add a jar to the classpath and you can even use it to bundle your app into a jar, war or ear of your own.

                        N.B. If it's just jsp's, servlets and regular classes then you probably want a war. An ear is designed for packaging up EJB's I believe. If you're using EJB's then you want your head seeing to.

                        Back to compiling from the command prompt...

                        I believe you can set the classpath in a parameter to the javac compiler. The parameter will look something like this:
                        -classpath c:/mydirectory/

                        If no classpath is set then it defaults to the current directory. Be warned that there may be an environment variable set on your system with some funny default. Using the -classpath parameter would override this.

                        Hope that helped some.
                        Ben

                        Comment

                        Working...
                        X