Hello. I am using a HashMap for inter-component communication from my ActionClass to
my BLB (Business Logic Bean) which connects to an Oracle DB to execute a query and
return a ResultSet.
Any assistance you can provide would be most appreciated.
Thanks in advance.
- Mitesh Kapadia
It seems as if I'm having problems returning the ResultSet because the following
condition in my ActionClass is not met:
if(facilList != null) {
target = "success" ;
session.setAttribute("facilTable" , facilList);
}
else {
target = "failure" ;
}
return (mapping.findForward(target));
Here is the code from my Business Logic Bean:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package net.reumann;
import java.io.*;
import java.util.ArrayList;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import net.reumann.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.commons.beanutils.BeanUtils;
public class OrgIdService {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ArrayList facilList = new ArrayList();
public ArrayList execute(DataHash beanHash) {
String facilId = (String) beanHash.get("FacilId");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =
DriverManager.getConnection("jdbc:oracle:thin:@sources:1521:TEST","Test1234","Test1234");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT FACIL_ID, FACIL_NAME,
ORG_ID FROM FACILITY");
while (rs.next()) {
FacilBean facil = new FacilBean();
facil.setFacilId(rs.getString("FACIL_ID"));
facil.setFacilName(rs.getString("FACIL_NAME"));
facil.setOrgId(rs.getString("ORG_ID"));
facilList.add(facil);
}
rs.close();
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the code from my ActionClass:
package net.reumann;
import java.io.*;
import java.util.ArrayList;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.commons.beanutils.BeanUtils;
import net.reumann.*;
public final class OrgIdAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Instantiate DataHash
DataHash dataHash = new DataHash();
// Retrieve the session object
HttpSession session = request.getSession(true);
String target = null;
// extract information from the LoginActionForm
String facilId = ((OrgIdActionForm)form).getFacilId();
//log.debug("FACILITY ID : " + facilId ) ;
//Instantiate OrgIdService BLB
OrgIdService service = new OrgIdService();
//Pass FacilId in DataHash
dataHash.put(Constants.DH_FacilId, facilId);
// Execute the call to the OrgIdService BLB
ArrayList facilList = new ArrayList();
facilList = service.execute(dataHash);
if(facilList != null) {
target = "success" ;
session.setAttribute("facilTable" , facilList);
}
else {
target = "failure" ;
}
return (mapping.findForward(target));
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the code from my FacilBean (being used as a DTO):
package net.reumann;
import java.beans.*;
public class FacilBean extends Object implements java.io.Serializable {
protected String facilId;
protected String facilName;
protected String orgId;
/** Getter for property facilId.
* @return Value of property facilId.
*
*/
public java.lang.String getFacilId() {
return facilId;
}
/** Setter for property facilId.
* @param facilId New value of property facilId.
*
*/
public void setFacilId(java.lang.String facilId) {
this.facilId = facilId;
}
/** Getter for property facilName.
* @return Value of property facilName.
*
*/
public java.lang.String getFacilName() {
return facilName;
}
/** Setter for property facilName.
* @param facilName New value of property facilName.
*
*/
public void setFacilName(java.lang.String facilName) {
this.facilName = facilName;
}
/** Getter for property orgId.
* @return Value of property orgId.
*
*/
public java.lang.String getOrgId() {
return orgId;
}
/** Setter for property orgId.
* @param orgId New value of property orgId.
*
*/
public void setOrgId(java.lang.String orgId) {
this.orgId = orgId;
}
}