GeeCON Prague 2014*
The moose likes Struts and the fly likes Connection Closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Connection Closed" Watch "Connection Closed" New topic
Author

Connection Closed

Judy001
Greenhorn

Joined: Jun 06, 2006
Posts: 4
Hi,
I am using Struts and jsp for my Screens. My Main Screen contains 8 buttons.
button.name= Name
button.address=Address
button.ids=IDs
button.url=URL....

When i press name button , it works fine .After that when i went for url or address or ids button iam getting error like
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:919)
at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:885)
at com.avox.struts.action.ButtonsAction.ids_button(ButtonsAction.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.LookupDispatchAction.execute
........
But when i stop and strt my tomcat, then another button works fine remaining are not working..
In struts-config.xml, my code look like this
<form-beans >
<form-bean name="ButtonsForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="names" type="java.util.ArrayList" />
<form-property name="addresses" type="java.util.ArrayList" />
<form-property name="legalnames" type="java.util.ArrayList" />
<form-property name="urls" type="java.util.ArrayList" />
<form-property name="ids" type="java.util.ArrayList" />
</form-bean>
....
<action
attribute="ButtonsForm"
input="/jsp/clientList.jsp"
name="ButtonsForm"
parameter="method"
path="/ButtonsAction"
scope="request"
type="com.avox.struts.action.ButtonsAction">
<forward
name="button_address"
path="/jsp/buttons/Address.jsp"
contextRelative="true" />
<forward
name="button_name"
path="/jsp/buttons/Name.jsp"
contextRelative="true" />
<forward
name="button_ids"
path="/jsp/buttons/Ids.jsp"
contextRelative="true" />
<forward
name="button_url"
path="/jsp/buttons/Url.jsp"
contextRelative="true" />

My action class
public class ButtonsAction extends LookupDispatchAction {

DBConnection db = new DBConnection();
CommonData cd = new CommonData();
OracleCallableStatement cstmt = null;
DataTGenericData genericData = null;
Connection conn = null;ResultSet rs=null;
public ButtonsAction() throws Exception{
db.init(); conn=db.getConnection();cd.init();
}

// Name Button
public ActionForward name_button(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
DynaActionForm ButtonsForm = (DynaActionForm) form;
. try {
mnames= new ArrayList(); int j=0;
cstmt =(OracleCallableStatement)conn.prepareCall
( "begin ? := pkg_csr_data.get_data2(?,?,?,?); end;" );
cstmt.registerOutParameter( 1,OracleTypes.STRUCT,"DATA_T_GENERIC_DATA");
........
........
mclients.add(new Mclient(result.toString()));
ButtonsForm.set("names",mnames);
}
cstmt.close();cstmt = null;
db.close(conn);
} catch (Exception e) {e.printStackTrace();}
finally {
if (cstmt != null) {
try {
cstmt.close();
} catch (SQLException e) {;}
}
}
return (mapping.findForward("button_name"));
}
public ActionForward address_button(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException, Exception
{
DynaActionForm ButtonsForm = (DynaActionForm) form;
try {
maddress= new ArrayList(); int j=0;
cstmt =(OracleCallableStatement)conn.prepareCall
( "begin ? := pkg_csr_data.get_data2(?,?,?,?); end;" );
cstmt.registerOutParameter( 1,OracleTypes.STRUCT,"DATA_T_GENERIC_DATA");
........
........
mclients.add(new Mclient(result.toString()));
ButtonsForm.set("addresses",maddress);
}
cstmt.close();cstmt = null;
db.close(conn);
} catch (Exception e) {e.printStackTrace();}
finally {
if (cstmt != null) {
try {
cstmt.close();
} catch (SQLException e) {;}
}
}
return (mapping.findForward("button_address"));
}
protected Map getKeyMethodMap()
{
Map map = new HashMap();
map.put("button.name","name_button");
map.put("button.address","address_button");
map.put("button.ids","ids_button");
map.put("button.url","url_button");
return map;
}
}
In my action class, i am instatiating my dynaction form every time. i think my error is due to that re-instatiation.i have to store all of my buttons data globally in diferent arraylists. i am trying to that but iam unable to retrive those data.

how can i solve this problem. I have spent 2 days for this error.still iam not getting right data.

Thanks in advance
SSSSjava stud
Greenhorn

Joined: Jun 06, 2006
Posts: 3
Hi Jyothi,
You have closed the connection in first method(name_button)itself. So you can't called that connection in second one(address_button). The solution is 'you have to open the connection once again, or keep the connection open'. i suggest that first one is better (correct me if i am wrong).
Judy001
Greenhorn

Joined: Jun 06, 2006
Posts: 4
Hi you are correct..I got it.i forgot about that.Many Thanks for your reply.
I have another doubt. In my address screen, i have 2 more buttons REG for register address and COR for correspondence address..when i press REG button i have to display all child's register addresses similarly COR button also. Before these buttons i have to populate master address. This master address works fine . but i don't know how to display these buttons's data in the same JSP.For this i have created action mapping like this...
<form-bean name="AddressForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="addresses" type="java.util.ArrayList" />
</form-bean>
<action
attribute="AddressForm"
input="/jsp/buttons/Address.jsp"
name="AddressForm"
parameter="method"
path="/AddressAction"
scope="request"
unknown="false"
type="com.avox.struts.action.AddressAction">
<forward
name="button_correspondence"
path="/jsp/buttons/Address.jsp"
contextRelative="true" />
<forward
name="button_register"
path="/jsp/buttons/Address.jsp"
contextRelative="true" />
</action>
</action-mappings>
I have written Address.jsp like this
<body>
Master Address: <br><br>
<CENTER>
<table border="1" width="60%" rules="none">
<logic:empty name="ButtonsForm" property="maddress" >
<tr>
<td> NO Master Address Available</td>
</tr>
</logic:empty>
<logic:notEmpty name="ButtonsForm" property="maddress" >
<logic:iterate name="ButtonsForm" property="maddress" id="address" >
<tr>
<td><bean:write name="address" property="address" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table>
<br><br><br>
<html:form action="/AddressAction">
<TABLE border="0" width="60%">
<TR>

<TD align="center">
<html:submit property="method">
<bean:message key="button.register"/>
</html:submit>
</TD>
<TD align="center">
<html:submit property="method">
<bean:message key="button.correspondence"/>
</html:submit>
</TD>
</TR>
</TABLE>
</html:form>
</center>
Children Addresses:
<CENTER><br><br>

<table border="1" width="60%" rules="none">
<logic:empty name="AddressForm" property="addresses" >
<tr>
<td> NO Children Address Available</td>
</tr>
</logic:empty>
<logic:notEmpty name="AddressForm" property="addresses" >
<logic:iterate name="AddressForm" property="addresses" id="address" >
<tr>
<td><bean:write name="addresses" property="address" /></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table>

</CENTER>
</body>
</html:html>

Master address's logic works fine but when i press REG button it shows error like this
Cannot find bean ButtonsForm in any scope
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:934)
at org.apache.struts.taglib.logic.EmptyTag.condition(EmptyTag.java:79)
at org.apache.struts.taglib.logic.EmptyTag.condition(EmptyTag.java:52)
at org.apache.struts.taglib.logic.ConditionalTagBase.doStartTag(ConditionalTagBase.java:174)
at org.apache.jsp.jsp.buttons.Address_jsp._jspx_meth_logic_empty_0(Address_jsp.java:315)
at org.apache.jsp.jsp.buttons.Address_jsp._jspService(Address_jsp.java:115)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Thanks in advance
SSSSjava stud
Greenhorn

Joined: Jun 06, 2006
Posts: 3
hi jyothi,

you try to call various dispatchAction's with use of JavaScript.
 
GeeCON Prague 2014
 
subject: Connection Closed