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");