Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java program is running .. But I am not getting my outputs in the JSP

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Java program is running .. But I am not getting my outputs in the JSP

    Folks

    I new to Java/jsp world. I used the existing Java code and jsp code modified very little. Basically the JSP and calling jar file with some PARM. jsp calling java JAR file (which in turn connecting to mainframe and submitting a job) How ever I am supposed to get those job messages to my jsp. Which is not a happening. Can you please help me in this regard.
    My JSP code is
    <%@ page import="java.util.*,java.io.*" %>
    <%
    String cmd = "D:\\java\\jre6\\bin\\java -jar D:\\webhome\\sites\\epsdev4\\webapps\\DB2\\db2live \\AdminJob.jar MAT2";
    String outstr = "";
    try {
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(cmd);
    try {
    InputStreamReader ise = new InputStreamReader(p.getErrorStream());
    BufferedReader bre = new BufferedReader(ise);
    InputStreamReader iso = new InputStreamReader(p.getInputStream());
    BufferedReader bro = new BufferedReader(iso);

    String line=null;
    while ( (line = bre.readLine()) != null ) {
    System.out.println( "ERR>" + line );
    }
    while ( (line = bro.readLine()) != null ) {
    System.out.println( "OUT>" + line );
    }

    }

    catch (IOException ioe)
    {
    ioe.printStackTrace();
    }

    int exitVal = p.waitFor();

    System.out.println( exitVal );
    }
    catch (Throwable t) {
    t.printStackTrace();
    }

    %>
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="../css/app.css" />
    <title> Generate Reports </title>
    </head>
    <h1 id="rpts_h1"> IMS DBD Report Retrieval </h1>
    <body>
    <form id="rpts_a_form">
    <textarea rows=35 cols=80 id="result_textarea">
    </textarea>
    </form>
    </body>
    </html>

    my Java code is:

    import java.sql.*;

    public class AdminJob {
    public static void main(String[] args)
    {
    Connection con = null;
    PreparedStatement ps = null;
    CallableStatement cs = null;
    ResultSet rs = null;
    String driver = "com.ibm.db2.jcc.DB2Driver";
    String url = "jdbc:db2://bzze.booven.com:3027/zzzD39A";
    String userid = "vxy4";
    String password = "sng6";
    // Parse arguments
    //if (args.length != 2)
    // {
    // //System.err.println("Usage: AdminJob <alias or //server/database> <userid><password>");
    // //System.err.println("where <alias or //server/database> is DB2 subsystem alias or //server/database for type 4 connectivity");
    // System.err.println(" <userid> is user ID to connect as");
    // System.err.println(" <password> is password to connect with");
    // return;
    // }
    //url += args[0];
    //userid = args[0];
    //password = args[1];
    try
    {
    String jobid = null;
    String[] jclstmt =
    {
    "//V331384D JOB (P,JVUP,BA3201),'ETRAK-DBA', ",
    "// NOTIFY=&SYSUID,MSGCLASS=T,MSGLEVEL=(1,1),TIME=1",
    "//*+JBS BIND D39A ",
    "//DELTAIMS EXEC PGM=DLAXVTB0,REGION=512K ",
    "//STEPLIB DD DISP=SHR,DSN=IMS.SYSTEM.RESLIB.STE ",
    "//DELTAPDS DD DISP=SHR,DSN=IMSMAT2.DVTF.DELTAPDS ",
    "//SYSPRINT DD SYSOUT=* ",
    "//SYSIN DD * ",
    " EXEC DISPCMD,IMSID=MAT2 ",
    "// "
    };
    int jobstatus = 0;
    int retrycount = 0;
    int rc = 0;
    String message = null;
    boolean hasResultSet = false;
    // Load the DB2 Universal JDBC Driver
    Class.forName(driver);
    //Class.forName("com.ibm.db2.jcc.*");
    // Connect to database
    System.out.println(" going to connect userig " + url + "userid " + userid + "password "+ password + ":");
    con = DriverManager.getConnection(url, userid, password);
    //con = DriverManager.getConnection("jdbc:db2j://baste.verizon.com:3027/DDF_D39A","v331384","samsung6");
    con.setAutoCommit(false);
    // Submit JCL
    ps = con.prepareStatement("INSERT INTO SYSIBM.JOB_JCL(ROWNUM, STMT) VALUES(?, ?)");
    for (int i = 0; i < jclstmt.length; i++)
    {
    ps.setInt(1, i + 1);
    ps.setString(2, jclstmt[i]);
    ps.execute();
    }
    cs = con.prepareCall("CALL SYSPROC.ADMIN_JOB_SUBMIT(?, ?, ?, ?, ?)");
    cs.setString(1, userid); // User ID
    cs.setString(2, password); // Password
    cs.registerOutParameter(3,Types.VARCHAR); // Job ID
    cs.registerOutParameter(4,Types.INTEGER); // Return code
    cs.registerOutParameter(5,Types.LONGVARCHAR); // Message area
    cs.execute();
    con.commit();
    // Obtain the return code
    rc = cs.getInt(4);

    if (rc > 0)
    {
    message = cs.getString(5);
    throw new AdminJobException(rc, "SYSPROC.ADMIN_JOB_SUBMIT execution failed: " + message);
    }
    else
    {
    jobid = cs.getString(3);
    System.out.println("Job " + jobid + " submitted successfully.");
    ps.close();
    cs.close();
    }
    /* Query job status */
    cs = con.prepareCall("CALL SYSPROC.ADMIN_JOB_QUERY(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
    cs.setString(1, userid); // User ID
    cs.setString(2, password); // Password
    cs.setString(3, jobid); // Job ID
    cs.registerOutParameter(4,Types.INTEGER); // Job status
    cs.registerOutParameter(5,Types.INTEGER); // Max RC
    cs.registerOutParameter(6,Types.INTEGER); // Completion type
    cs.registerOutParameter(7,Types.INTEGER); // System abend code
    cs.registerOutParameter(8,Types.INTEGER); // User abend code
    cs.registerOutParameter(9,Types.INTEGER); // Return code
    cs.registerOutParameter(10,Types.LONGVARCHAR); // Message area
    while (true)
    {
    cs.execute();
    con.commit();
    // Obtain return code
    rc = cs.getInt(9);
    if (rc > 4)
    {
    message = cs.getString(10);
    throw new AdminJobException(rc, "SYSPROC.ADMIN_JOB_QUERY execution failed:" +message);
    }
    else
    {
    jobstatus = cs.getInt(4);
    if (rc == 0)
    {
    // The job is in the OUTPUT queue
    if (jobstatus == 3)
    {
    System.out.println("Job " + jobid + " finished execution. Job completion information: ");
    System.out.println(" Max RC: " + cs.getInt(5));
    System.out.println(" Completion type: " + cs.getInt(6));
    System.out.println(" System abend code: " + cs.getInt(7));
    System.out.println(" User abend code: " + cs.getInt(8));
    break;
    }

    else if (jobstatus == 1 || jobstatus == 2)
    {
    // The job is in the INPUT or ACTIVE queue
    System.out.println("Job " + jobid + " is in the " + (jobstatus == 1 ? "INPUT": "ACTIVE") + " queue. Waiting for job to finish...");
    Thread.sleep(1000);
    continue;
    }
    }
    else if (rc == 4)
    {
    if (jobstatus == 5)
    {
    // The job is in an unknown phase
    System.out.println("Job " + jobid + " is in an unknown phase. Waiting for job to finish...");
    Thread.sleep(1000);
    continue;
    }
    else if (jobstatus == 4)
    {
    if (retrycount == 10)
    throw new AdminJobException(rc, "Job " + jobid + " not found:" + message);
    else
    {
    System.out.println("Job " + jobid + " not found. Waiting for job...");
    Thread.sleep(1000);
    retrycount++;
    continue;
    }
    }
    }
    }
    }
    cs.close();
    System.out.println("Job " + jobid + " has finished and has output to be fetched.");
    // Fetch job output
    cs = con.prepareCall("CALL SYSPROC.ADMIN_JOB_FETCH(?, ?, ?, ?, ?)");
    cs.setString(1, userid); // User ID
    cs.setString(2, password); // Password
    cs.setString(3, jobid); // Job ID
    cs.registerOutParameter(4,Types.INTEGER); // Return code
    cs.registerOutParameter(5,Types.LONGVARCHAR); // Message area
    hasResultSet = cs.execute();
    con.commit();
    // Obtain return code
    rc = cs.getInt(4);
    if (rc > 0)
    {
    message = cs.getString(5);
    throw new AdminJobException(rc, "SYSPROC.ADMIN_JOB_FETCH execution failed: " +message);
    }
    else
    {
    if (hasResultSet)
    {
    rs = cs.getResultSet();
    while (rs.next())
    {
    System.out.println(rs.getString(2));
    }
    rs.close();
    }
    cs.close();
    }
    // Purge job output
    cs = con.prepareCall("CALL SYSPROC.ADMIN_JOB_CANCEL(?, ?, ?, ?, ?, ?)");
    cs.setString(1, userid); // User ID
    cs.setString(2, password); // Password
    cs.setInt(3, 2); // Processing option (Cancel=1,Purge=2)
    cs.setString(4, jobid); // Job ID
    cs.registerOutParameter(5,Types.INTEGER); // Return code
    cs.registerOutParameter(6,Types.LONGVARCHAR); // Message area
    cs.execute();
    con.commit();
    // Obtain return code
    rc = cs.getInt(5);
    if (rc > 0)
    {
    message = cs.getString(6);
    throw new AdminJobException(rc, "SYSPROC.ADMIN_JOB_CANCEL execution failed: " +message);
    }
    else
    {
    System.out.println("Job " + jobid + " has been purged.");
    cs.close();
    }
    }
    catch (AdminJobException aje)
    {
    System.err.println("Program error: rc=" + aje.getRC() + " message=" + aje.getMessage());
    }
    catch (ClassNotFoundException e)
    {
    System.err.println("Could not load JDBC driver");
    System.err.println("Exception: " + e);
    e.printStackTrace();
    }
    catch (SQLException sqle)
    {
    System.err.println("SQLException information");
    System.err.println("Error msg: " + sqle.getMessage());
    System.err.println("SQLSTATE: " + sqle.getSQLState());
    System.err.println("Error code: " + sqle.getErrorCode());
    }
    catch (Exception e)
    {
    System.err.println("Error: message=" + e.getMessage());
    }
    finally
    {
    // Release resources and disconnect
    try
    {
    ps.close();
    } catch (Exception e)
    {
    }
    try
    {
    rs.close();
    } catch (Exception e)
    {
    }
    try
    {
    cs.close();
    } catch (Exception e)
    {
    }
    try
    {
    con.close();
    } catch (Exception e)
    {
    }
    }
    }
    }

    class AdminJobException extends Exception {
    private int rc;

    AdminJobException(int rc, String message) {
    super(message);
    this.rc = rc;
    }

    public int getRC() {
    return rc;
    }
    }



    Thank you all in advance

    Ravi


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java program is running .. But I am not getting my outputs in the JSP

    Please wrap [code=java] C O D E [/code] tags around your code...
     C O D E

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java program is running .. But I am not getting my outputs in the JSP

    can you please tell me what/where this one has to be coded in java code or JSP
    Thank You

Similar Threads

  1. Entering and running a Program
    By Bijaysadhok in forum Java Theory & Questions
    Replies: 1
    Last Post: February 23rd, 2012, 07:15 AM
  2. Running into a problem with my program.
    By letsgetlifted in forum What's Wrong With My Code?
    Replies: 9
    Last Post: December 9th, 2011, 07:09 PM
  3. Is there a way I could create/get a program that outputs a form in BBC?
    By Elite Cow in forum Java Theory & Questions
    Replies: 5
    Last Post: October 11th, 2011, 01:01 PM
  4. New to Java Can not figure out how to create a table with my codes outputs!
    By shoppa028 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 12th, 2011, 09:21 AM
  5. Replies: 3
    Last Post: February 23rd, 2011, 01:27 AM