You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by AKEDJO Guy-Patrick <ak...@yahoo.com> on 2004/07/03 05:21:38 UTC

javax.servlet.ServletException: Cannot find bean dblist in scope request

I've been trying to solve that issue for 3 days now I went also to the Net trying to find all information related to this but no way. I tried everything I know and all I found out but the error still the same.
Can you help me please.
Here are some information you need to check my code.
 
============================= The error message=====================
javax.servlet.ServletException: Cannot find bean dblist in scope request
 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
 org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
 org.apache.jsp.form.list_jsp._jspService(list_jsp.java:129)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause 
javax.servlet.jsp.JspException: Cannot find bean dblist in scope request
 org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:940)
 org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:277)
 org.apache.jsp.form.list_jsp._jspService(list_jsp.java:85)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 
====================Action class XML config================
<action path="/list" type="com.youcompany.struts.action.ListAction" validate="false">
<forward name="listok" path="/form/list.jsp" />
</action>
========================my Action class==================
 
package com.youcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.youcompany.struts.bean.*;
import javax.sql.*;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import java.util.ArrayList;
import java.util.Collection;
 
public class ListAction extends Action {
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/** 
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// throw new UnsupportedOperationException("Generated method 'execute(...)' not implemented.");
 
// Get the datasource 
ActionErrors errors = new ActionErrors();
DatabaseDVDManager DAOdvd = new DatabaseDVDManager();
DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
Collection c = new ArrayList();

try {
// connection
DAOdvd.setDataSource(dataSource);
c = DAOdvd.getAll();
 

} catch (DAOException e) {
// Message for the user:
errors.add("label", new ActionError("error.listfailed"));
saveErrors(request, errors);

// Logging the error:
String message = "DVDs could not be listed";

// Save the chained exceptions:
request.setAttribute("MYEXCEPTION", new DAOException(message, e));

}

request.setAttribute("dblist",c);

return (mapping.findForward("listok"));
 
}
}
===================================My Jsp for the view ==============
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
 
<h2>DVD library</h2>
<p>
Click on Id to edit DVD.</p>
<table border=1 bgcolor="#FFFFCC">
<tr>
<th>Id</th>
<th>Title</th>
</tr>
<logic:iterate id="dvd" name="dblist" scope="request"
type="com.youcompany.struts.bean.DVD">
<tr>
<td><a href="list.do?id=<bean:write name="dvd" property="id"/>">
<bean:write name="dvd" property="id"/></a></td>
<td><bean:write name="dvd" property="title"/></td>
</tr>
</logic:iterate>
</table>
 
=============My DVD bean:==========================

import java.io.Serializable;
/*
* This a bean - and also a Value - or Data Transfer Object 
*/
public class DVD implements Serializable {
private String id;
private String title;

public DVD() {
}

public DVD(String id, String title) {
setId(id);
setTitle(title);
}

public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
 
============================my DAO========================
 
package com.youcompany.struts.bean;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import javax.sql.DataSource;

public class DatabaseDVDManager implements DVDManagerIF {
private DataSource dataSource;
 
// Contains en Exception when an error has occured 
private Exception error;
// Contains an error message
private String message;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public void createDVD(String id, String title) throws DAOException {
if (getDVD(id) != null) throw new DAOException("Id " + id + " is already used");
Connection conn = null;
PreparedStatement pstmt = null;
error = null;

try {
conn = dataSource.getConnection();

// Prepare a statement to insert a record
String sql = "INSERT INTO dvd (id, title) VALUES(?, ?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.setString(2, title);
pstmt.executeUpdate();
} catch (SQLException e) {
error = e;
message = "Create failed";
}
closePrep(pstmt);
closeConnection(conn);
checkOK(); 
}
public DVD getDVD(String id) throws DAOException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet result = null;
error = null;
DVD dvd = null;

try {
conn = dataSource.getConnection();

// Prepare a statement to insert a record
String sql = "SELECT * FROM dvd WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
result = pstmt.executeQuery();
if (result.next()) {
String newId = result.getString("id");
String title = result.getString("title");
dvd = new DVD(newId, title);
}
} catch (SQLException e) {
error = e;
message = "Read failed";
}

closeResult(result);
closePrep(pstmt);
closeConnection(conn);
checkOK(); 

return dvd; 
}
public void updateDVD(String id, String title) throws DAOException {
if (getDVD(id) == null) throw new DAOException("Id " + id + " was not found");
Connection conn = null;
PreparedStatement pstmt = null;
error = null;

try {
conn = dataSource.getConnection();

// Prepare a statement to update a record
String sql = "UPDATE dvd SET title=? WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, title);
pstmt.setString(2, id);
pstmt.executeUpdate();
} catch (SQLException e) {
error = e;
message = "Update failed";
}
closePrep(pstmt);
closeConnection(conn);
checkOK(); 
}
public void deleteDVD(String id) throws DAOException {
if (getDVD(id) == null) throw new DAOException("Id " + id + " was not found");
Connection conn = null;
PreparedStatement pstmt = null;
error = null;

try {
conn = dataSource.getConnection();

// Prepare a statement to delete a record
String sql = "DELETE FROM dvd WHERE id=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, id);
pstmt.executeUpdate();
} catch (SQLException e) {
error = e;
message = "Delete failed";
}
closePrep(pstmt);
closeConnection(conn);
checkOK(); 

}
public Collection getAll() throws DAOException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
error = null;
Collection c = new ArrayList();

try {
conn = dataSource.getConnection();

// Prepare a statement to list a record
String sql = "SELECT * FROM dvd";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(sql);
while (rs.next()) {
String id = rs.getString("id");
String title = rs.getString("title");
DVD dvd = new DVD(id, title);
c.add(dvd);
} 
} catch (SQLException e) {
error = e;
message = "Getall failed";
}
closeResult(rs);
closePrep(pstmt);
closeConnection(conn);
checkOK(); 
return c;

}
public Collection findDVDTitle(String findTitle) throws DAOException {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
error = null;
Collection c = new ArrayList();

try {
conn = dataSource.getConnection();

// Prepare a statement to find a record
String sql = "SELECT * FROM dvd";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(sql);
while (rs.next()) {
String id = rs.getString("id");
String title = rs.getString("title");
DVD dvd = new DVD(id, title);
if (dvd.getTitle().toUpperCase().indexOf(findTitle.toUpperCase()) > -1) {
c.add(dvd);
}
} 
} catch (SQLException e) {
error = e;
message = "Find failed";
}
closeResult(rs);
closePrep(pstmt);
closeConnection(conn);
checkOK(); 
return c;

}

private void checkOK() throws DAOException {
if (error != null) {
throw new DAOException(message, error);
}
}

private void closeConnection(Connection connection) {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
if (error == null) {
error = e;
message = "Close conn failed";
}
}
}
}
private void closePrep(PreparedStatement prep) {
if (prep != null) {
try {
prep.close();
} catch (SQLException e) {
if (error == null) {
error = e;
message = "Close prep failed";
}
}
}
}

private void closeResult(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
if (error == null) {
error = e;
message = "Close result failed";
}
}
}
}
}
 
Best regards

 
 

		
---------------------------------
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.

Re: javax.servlet.ServletException: Cannot find bean dblist in scope request

Posted by Dave Gynn <dg...@yahoo.com>.
Make sure that you are requesting the URL that invokes the Action.  The 
error that you are seeing would happen if you request the JSP directly.
So request http://yourserver/yourapp/list.do
and not http://yourserver/yourapp/form/list.jsp

AKEDJO Guy-Patrick wrote:
> I've been trying to solve that issue for 3 days now I went also to the Net trying to find all information related to this but no way. I tried everything I know and all I found out but the error still the same.
> Can you help me please.
> Here are some information you need to check my code.
>  
> ============================= The error message=====================
> javax.servlet.ServletException: Cannot find bean dblist in scope request
>  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
>  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
>  org.apache.jsp.form.list_jsp._jspService(list_jsp.java:129)
>  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
>  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
>  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
> 
> root cause 
> javax.servlet.jsp.JspException: Cannot find bean dblist in scope request
>  org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:940)
>  org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:277)
>  org.apache.jsp.form.list_jsp._jspService(list_jsp.java:85)
>  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
>  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
>  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: javax.servlet.ServletException: Cannot find bean dblist in scope request

Posted by Robert Taylor <rt...@mulework.com>.
Okay. As I understand it, you have an action which retrieves information from the database
and places it in the request scope under the name "dblist" and then forwards to  page 
which should iterate over the list and render its contents.

The problem you are having is that the iterate tag cannot find a "dblist" in the request scope.


To start you could remove all the database access stuff in ListAction and place a dummy collection in request
scope and forward (not redirect) to the page which renders the data.

I would also print to a log file so that you can more easily debug the problem. It appears that you log an
error message to request scope and I assume something else uses that information. Try using Log4J or if nothing
else catch the exception and issue a printStackTrace().

I bet an exception is occurring but the error is not being reported for some reason.

robert

> -----Original Message-----
> From: AKEDJO Guy-Patrick [mailto:akpatk@yahoo.com]
> Sent: Friday, July 02, 2004 11:22 PM
> To: user@struts.apache.org
> Subject: javax.servlet.ServletException: Cannot find bean dblist in
> scope request
> 
> 
> I've been trying to solve that issue for 3 days now I went also to the Net trying to find all information related to this 
> but no way. I tried everything I know and all I found out but the error still the same.
> Can you help me please.
> Here are some information you need to check my code.
>  
> ============================= The error message=====================
> javax.servlet.ServletException: Cannot find bean dblist in scope request
>  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
>  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
>  org.apache.jsp.form.list_jsp._jspService(list_jsp.java:129)
>  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
>  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
>  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
> 
> root cause 
> javax.servlet.jsp.JspException: Cannot find bean dblist in scope request
>  org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:940)
>  org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:277)
>  org.apache.jsp.form.list_jsp._jspService(list_jsp.java:85)
>  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
>  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
>  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
>  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>  
> ====================Action class XML config================
> <action path="/list" type="com.youcompany.struts.action.ListAction" validate="false">
> <forward name="listok" path="/form/list.jsp" />
> </action>
> ========================my Action class==================
>  
> package com.youcompany.struts.action;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import org.apache.struts.action.Action;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> import com.youcompany.struts.bean.*;
> import javax.sql.*;
> import org.apache.struts.action.ActionError;
> import org.apache.struts.action.ActionErrors;
> import java.util.ArrayList;
> import java.util.Collection;
>  
> public class ListAction extends Action {
> // --------------------------------------------------------- Instance Variables
> // --------------------------------------------------------- Methods
> /** 
> * Method execute
> * @param ActionMapping mapping
> * @param ActionForm form
> * @param HttpServletRequest request
> * @param HttpServletResponse response
> * @return ActionForward
> * @throws Exception
> */
> public ActionForward execute(
> ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws Exception {
> // throw new UnsupportedOperationException("Generated method 'execute(...)' not implemented.");
>  
> // Get the datasource 
> ActionErrors errors = new ActionErrors();
> DatabaseDVDManager DAOdvd = new DatabaseDVDManager();
> DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
> Collection c = new ArrayList();
> 
> try {
> // connection
> DAOdvd.setDataSource(dataSource);
> c = DAOdvd.getAll();
>  
> 
> } catch (DAOException e) {
> // Message for the user:
> errors.add("label", new ActionError("error.listfailed"));
> saveErrors(request, errors);
> 
> // Logging the error:
> String message = "DVDs could not be listed";
> 
> // Save the chained exceptions:
> request.setAttribute("MYEXCEPTION", new DAOException(message, e));
> 
> }
> 
> request.setAttribute("dblist",c);
> 
> return (mapping.findForward("listok"));
>  
> }
> }
> ===================================My Jsp for the view ==============
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
>  
> <h2>DVD library</h2>
> <p>
> Click on Id to edit DVD.</p>
> <table border=1 bgcolor="#FFFFCC">
> <tr>
> <th>Id</th>
> <th>Title</th>
> </tr>
> <logic:iterate id="dvd" name="dblist" scope="request"
> type="com.youcompany.struts.bean.DVD">
> <tr>
> <td><a href="list.do?id=<bean:write name="dvd" property="id"/>">
> <bean:write name="dvd" property="id"/></a></td>
> <td><bean:write name="dvd" property="title"/></td>
> </tr>
> </logic:iterate>
> </table>
>  
> =============My DVD bean:==========================
> 
> import java.io.Serializable;
> /*
> * This a bean - and also a Value - or Data Transfer Object 
> */
> public class DVD implements Serializable {
> private String id;
> private String title;
> 
> public DVD() {
> }
> 
> public DVD(String id, String title) {
> setId(id);
> setTitle(title);
> }
> 
> public String getId() {
> return id;
> }
> public void setId(String id) {
> this.id = id;
> }
> public String getTitle() {
> return title;
> }
> public void setTitle(String title) {
> this.title = title;
> }
> }
>  
> ============================my DAO========================
>  
> package com.youcompany.struts.bean;
>  
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.util.ArrayList;
> import java.util.Collection;
> import javax.sql.DataSource;
> 
> public class DatabaseDVDManager implements DVDManagerIF {
> private DataSource dataSource;
>  
> // Contains en Exception when an error has occured 
> private Exception error;
> // Contains an error message
> private String message;
> public void setDataSource(DataSource dataSource) {
> this.dataSource = dataSource;
> }
> public void createDVD(String id, String title) throws DAOException {
> if (getDVD(id) != null) throw new DAOException("Id " + id + " is already used");
> Connection conn = null;
> PreparedStatement pstmt = null;
> error = null;
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to insert a record
> String sql = "INSERT INTO dvd (id, title) VALUES(?, ?)";
> pstmt = conn.prepareStatement(sql);
> pstmt.setString(1, id);
> pstmt.setString(2, title);
> pstmt.executeUpdate();
> } catch (SQLException e) {
> error = e;
> message = "Create failed";
> }
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> }
> public DVD getDVD(String id) throws DAOException {
> Connection conn = null;
> PreparedStatement pstmt = null;
> ResultSet result = null;
> error = null;
> DVD dvd = null;
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to insert a record
> String sql = "SELECT * FROM dvd WHERE id=?";
> pstmt = conn.prepareStatement(sql);
> pstmt.setString(1, id);
> result = pstmt.executeQuery();
> if (result.next()) {
> String newId = result.getString("id");
> String title = result.getString("title");
> dvd = new DVD(newId, title);
> }
> } catch (SQLException e) {
> error = e;
> message = "Read failed";
> }
> 
> closeResult(result);
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> 
> return dvd; 
> }
> public void updateDVD(String id, String title) throws DAOException {
> if (getDVD(id) == null) throw new DAOException("Id " + id + " was not found");
> Connection conn = null;
> PreparedStatement pstmt = null;
> error = null;
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to update a record
> String sql = "UPDATE dvd SET title=? WHERE id=?";
> pstmt = conn.prepareStatement(sql);
> pstmt.setString(1, title);
> pstmt.setString(2, id);
> pstmt.executeUpdate();
> } catch (SQLException e) {
> error = e;
> message = "Update failed";
> }
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> }
> public void deleteDVD(String id) throws DAOException {
> if (getDVD(id) == null) throw new DAOException("Id " + id + " was not found");
> Connection conn = null;
> PreparedStatement pstmt = null;
> error = null;
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to delete a record
> String sql = "DELETE FROM dvd WHERE id=?";
> pstmt = conn.prepareStatement(sql);
> pstmt.setString(1, id);
> pstmt.executeUpdate();
> } catch (SQLException e) {
> error = e;
> message = "Delete failed";
> }
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> 
> }
> public Collection getAll() throws DAOException {
> Connection conn = null;
> PreparedStatement pstmt = null;
> ResultSet rs = null;
> error = null;
> Collection c = new ArrayList();
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to list a record
> String sql = "SELECT * FROM dvd";
> pstmt = conn.prepareStatement(sql);
> rs = pstmt.executeQuery(sql);
> while (rs.next()) {
> String id = rs.getString("id");
> String title = rs.getString("title");
> DVD dvd = new DVD(id, title);
> c.add(dvd);
> } 
> } catch (SQLException e) {
> error = e;
> message = "Getall failed";
> }
> closeResult(rs);
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> return c;
> 
> }
> public Collection findDVDTitle(String findTitle) throws DAOException {
> Connection conn = null;
> PreparedStatement pstmt = null;
> ResultSet rs = null;
> error = null;
> Collection c = new ArrayList();
> 
> try {
> conn = dataSource.getConnection();
> 
> // Prepare a statement to find a record
> String sql = "SELECT * FROM dvd";
> pstmt = conn.prepareStatement(sql);
> rs = pstmt.executeQuery(sql);
> while (rs.next()) {
> String id = rs.getString("id");
> String title = rs.getString("title");
> DVD dvd = new DVD(id, title);
> if (dvd.getTitle().toUpperCase().indexOf(findTitle.toUpperCase()) > -1) {
> c.add(dvd);
> }
> } 
> } catch (SQLException e) {
> error = e;
> message = "Find failed";
> }
> closeResult(rs);
> closePrep(pstmt);
> closeConnection(conn);
> checkOK(); 
> return c;
> 
> }
> 
> private void checkOK() throws DAOException {
> if (error != null) {
> throw new DAOException(message, error);
> }
> }
> 
> private void closeConnection(Connection connection) {
> if (connection != null) {
> try {
> connection.close();
> } catch (SQLException e) {
> if (error == null) {
> error = e;
> message = "Close conn failed";
> }
> }
> }
> }
> private void closePrep(PreparedStatement prep) {
> if (prep != null) {
> try {
> prep.close();
> } catch (SQLException e) {
> if (error == null) {
> error = e;
> message = "Close prep failed";
> }
> }
> }
> }
> 
> private void closeResult(ResultSet rs) {
> if (rs != null) {
> try {
> rs.close();
> } catch (SQLException e) {
> if (error == null) {
> error = e;
> message = "Close result failed";
> }
> }
> }
> }
> }
>  
> Best regards
> 
>  
>  
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail - You care about security. So do we.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org