You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Patrick Beagan <pb...@advisortech.com> on 2002/12/09 21:35:20 UTC

getDataSource() compile problem

Hi.  I am trying to connect to an Oracle database for a simple 
prove-out.  I have copied the sample code in the Strut's user guide but am 
getting compile time errors.   Any Ideas?  Is there a better resource for 
Struts example code or DBCP commons examples?  I think the list archive 
search is broken, not returning any results for 'datasource'.  Thanks - Patrick

Compile error:
     [javac] 
/export/home/patrick/dev/myapp/src/play/test/ShowUsersAction.java:26: 
cannot resolve symbol
     [javac] symbol  : method 
getDataSource  (javax.servlet.http.HttpServletRequest)
     [javac] location: class play.test.ShowUsersAction
     [javac]                dataSource = getDataSource(request);
     [javac]                             ^
     [javac] 1 error

Code:
public final class ShowUsersAction extends Action {
      public ActionForward perform(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response) {

           // database access
           javax.sql.DataSource dataSource;
           java.sql.Connection myConnection;

           try {
                dataSource = getDataSource(request);
                myConnection = dataSource.getConnection();
                getServlet().log("Acquired Connection.");

           } catch (SQLException se) {
                getServlet().log("Connection.process", se);
           } finally {
                try {
                     myConnection.close();
                     getServlet().log("Closed Connection.");
                } catch (SQLException e) {
                     getServlet().log("Connection.close", e);
                }
           }

           return (mapping.findForward("success"));
      }
}



struts-config.xml:

   <data-source type="org.apache.commons.dbcp.BasicDataSource">
     <set-property property="driverClassName"
       value="oracle.jdbc.driver.OracleDriver" />
     <set-property property="url"
       value="sql:oracle:thin:@mach:1521:db1" />
     <set-property
       property="maxActive"
       value="10" />
     <set-property
       property="maxWait"
       value="5000" />
     <set-property
       property="defaultAutoCommit"
       value="false" />
     <set-property
       property="defaultReadOnly"
       value="false" />
   </data-source>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>