struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ricky" <>
Subject HELP: about to get datasource of struts and pass to logic beans...
Date Thu, 01 Jan 1970 00:00:00 GMT
hi, there, 

    with my project i had several queries about get datasource in struts. i know how to get
datasource in struts, just as in myAction, use getDataSource method and return DataSource
object, and go on to get connection .... 

    i also know the logic beans between the Controller and Module, so i create a logic bean
,i don't know how to get datasourc of pass the datasource, in some tutorial , i got a way
to solve this, create a method getDAO(HttpServletRequest request) and pass the request to
the method to get DataSource, i was lost here, i dont' know what should i return in getDAO,
should i return a DataSource object or others and in my logic bean i can use the datasource
and also get connection , statement and resultset object , there i have to close it after
i finish my process ....what do you think of this i did ? in general, when i got a DataSource,
i will got a connection from datasource and a PrepareStatement and also a ResultSet , when
i finished my process, i can close all object i opened before in final method of try ...catch...experession..
now what should i do to return a proper object in getDAO method and in logic beans i can use
the object to process logic business...

i appologized for this ... i hope you can give me some suggestion or flow...... thanx!

now here is my flow of struts framework to pass the datasource to the logic beans...  i hope
you can reword if you have some good idea...of correct my mistake... :)

    myAction :

    myAction extends Action() {
      public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response) {
        LogicBean bean = new LogicBean();
        Object objcet = bean.doMethod(getDAO(request), other param)
      public DataSource getDAO(HttpServletRequest request) {
        DataSource ds = null;
        ds = getDataSource(request);
        return ds;

    and in my logic bean :

    class LogicBean {
      public Objct doMethod(DataSource ds, other param) {
        try {
          Connection conn = ds.getConnection();
          PrepareStatment stmt = conn.prepareStatment("SELECT .......");
          ResultSet rs = stmt.executeQuery();
          return Object.....;
        } catch (SQLException ex) {
        } final {
          try {
          } catch (Exception ex) {
        return null;

    should i pass the DataSource to my logic beans? otherwise what object should i pass....

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message