Sunday, February 22, 2009

Java on Mainframe OS

User from the Web can initiate a transaction that might communicate with a mainframe database (DB2®, Information Management System (IMS), and so forth), or even with a Virtual Storage Access Method (VSAM) file. As a result, the mainframe then returns the data in a well-formatted Web page. The Web user can also initiate an update on the mainframe database as well.

On one side, you have the highly robust and scalable mainframe. On the other, you have the flexibility of Java and the Web world. As noted above, a typical Web application would initiate a transaction that would do a one-off database access.

The Java solution to submit the batch jobs from a Z/OS mainframe.

package fileTransferProtocol;
import org.apache.commons.net.ftp.*;
import java.io.*;
public class FileTransferProtocol {
public static void main (String [ ] args) {
String serverName ="my.zos.mainframe" ;
String userName ="userid" ;
String password ="********" ;
FTPClient ftp = new FTPClient() ;
//Connect to the server
try {
ftp.connect (serverName) ;
String replyText =ftp.getReplyString() ;
System.out.println (replyText) ;
}
catch (Exception e) {
e.printStackTrace () ;
}
//Login to the server
try {
ftp.login (userName, password) ;
String replyText =
ftp.getReplyString() ;
System.out.println (replyText);
} catch (Exception e) {
e.printStackTrace();
}
//Tell server that the file will have JCL records
try {
ftp.site ("filetype=jes") ;
String replyText =
ftp.getReplyString() ;
System.out.println (replyText) ;
}
catch (Exception e) {
e.printStackTrace() ;
}
//Submit the job from the text file.Use \\ to avoid using escape notation
try {
FileInputStream inputStream = new FileInputStream ("C:\\job.txt") ;
ftp.storeFile (serverName,inputStream) ;
String replyText =
ftp.getReplyString() ;
System.out.println (replyText) ;
}
catch (Exception e) {
e.printStackTrace() ;
}
//Quit the server
try {
ftp.quit();
}
catch (Exception e) {
e.printStackTrace() ;
}
}
}

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory