502 IMS Connectivity in an On Demand Environment: A Practical Guide to IMS Connectivity
System.out.println("IMS RDS Servlet : Caught exception in final section is: " + t);
arg0.setAttribute("t",t.getMessage());
RequestDispatcher disp = arg0.getRequestDispatcher("Output.jsp");
System.out.println("IMS RDS Servlet : Success Dispatch Result");
System.out.println("IMS RDS Servlet : End" );
disp.forward(arg0,arg1);
}
}
}
}
ImsJavaRdsSample.java
ImsJavaRdsSample.java is the servlet for the IMS JDBC access with the local transaction
semantics, as shown in Example B-2.
Example: B-2 ImsJavaRdsSample.java
package imsRds;
import java.io.IOException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import javax.sql.*;
public class ImsRdsSample extends HttpServlet implements Servlet {
DataSource dataSource;
public void init() throws ServletException {
try {
//Obtain the initial JNDI Naming context for JDBC Connection
System.out.println("IMS RDS Servlet : Start ");
Context initialContext = new InitialContext();
dataSource = (DataSource)initialContext.lookup("java:comp/env/imsjavaRDSRedBook");
System.out.println("IMS RDS Servlet : Success Create DataSource");
}catch (Exception e){
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
Connection connection = null;
Statement statement = null;
ResultSet results = null;
String LastName = null;
Appendix B. IMS RDS application example 503
String FirstName = null;
String Extension = null;
String ZipCode = null;
try{
//Get JDBC Conneciton
connection = dataSource.getConnection();
System.out.println("IMS RDS Servlet : Success Get Connection");
//Get Key Value from Input Page
String keyValue = arg0.getParameter("keyValue").trim();
//Issue SQL
String queryString = "SELECT * FROM PhoneBook.Person "
+ "WHERE Person.LastName = '" + keyValue + "'";
statement = connection.createStatement();
results = statement.executeQuery(queryString);
//Get Output
while(results.next()) {
LastName = results.getString("Person.LastName");
FirstName = results.getString("Person.FirstName");
Extension = results.getString("Person.Extension");
ZipCode = results.getString("Person.ZipCode");
}
System.out.println("IMS RDS Servlet : Success Get Result");
//Commit LocalTransaction
connection.commit();
System.out.println("IMS RDS Servlet : Success Commit LocalTransaction");
//Set the result to the JSP
arg0.setAttribute("OUT__LastName", LastName);
arg0.setAttribute("OUT__FirstName", FirstName);
arg0.setAttribute("OUT__Extension", Extension);
arg0.setAttribute("OUT__ZipCode", ZipCode);
} catch (Exception e) {
try{
//RollBack LocalTransaciton
connection.rollback();
System.out.println("IMS RDS Servlet : Success Rollback LocalTransaction");
//Close JDBC Resources
if (statement != null) {statement.close();}
if (connection != null) {connection.close();}
System.out.println("IMS RDS Servlet : Caught exception in main section is: " + e);
arg0.setAttribute("e",e.getMessage());
} catch (Exception s){
System.out.println("IMS RDS Servlet : Caught exception in rollback section is: " + s);
arg0.setAttribute("s",s.getMessage());
}
} finally {
try{
//Close JDBC Resources
if (statement != null) {statement.close();}
if (connection != null) {connection.close();}
RequestDispatcher disp = arg0.getRequestDispatcher("Output.jsp");
disp.forward(arg0,arg1);
System.out.println("IMS RDS Servlet : Success Dispatch Result");

Get IMS Connectivity in an On Demand Environment: A Practical Guide to IMS Connectivity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.