This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Database Pooling in Struts

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm following the tutorial from the book "Jakarta Struts Live� and I have problems connecting to my database (Struts 1.1):

================================
This is the code inside the Action class:
...
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

UserRegistrationForm userForm = (UserRegistrationForm) form;
DataSource dataSource = getDataSource(request, "userDB"); // *** ERROR: GETS A NULL ***
Connection conn = dataSource.getConnection();
...
================================
The data-sources in struts-config.xml:
...
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource" key="userDB">
<set-property property="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver" />
<set-property property="url" value="jdbc dbc atosStruts" />
<set-property property="username" value="jose" />
<set-property property="password" value="jose" />
</data-source>
</data-sources>
...
================================
The init-param in web.xml:
...
<init-param>
<param-name>config</param-name>
<param-value>WEB-INF/struts-config.xml</param-value>
</init-param>
...
================================

The problem seems to be that the code in the Action class (above)

DataSource dataSource = getDataSource(request, "userDB");

returns a null.

I've debugged the application and I've realized that, inside the Struts getDataSource method, the ServletContext doesn't contain the "userDB" attribute.

Any help?

Thanks.
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind, everything was correct. It was my IDE which deleted the <data-source>.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic