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