Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Problem in Struts Application while connecting to database

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to struts application, while i am connecting my application to database, using this code
connection = DriverManager.getConnection("jdbc dbc:StrutsData");
-its' work fine , but when i am using struts-config.xml data source code tomcat display following error and i get one more error message in my Action class that is
datasource = getDataSource(request); (in this line i show The method getDataSource(HttpServletRequest) is undefined for the type LoginAction) error , so anybody please help me..

May 30, 2007 2:33:51 PM org.apache.struts.action.ActionServlet initApplicationDa
SEVERE: Initializing application data source org.apache.struts.action.DATA_SOURC
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.jav
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.
at org.apache.struts.action.ActionServlet.initApplicationDataSources(Act
at org.apache.struts.action.ActionServlet.init(
at javax.servlet.GenericServlet.init(
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
at org.apache.catalina.core.StandardWrapper.load(
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
at org.apache.catalina.core.StandardContext.start(
at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(

at org.apache.catalina.core.StandardHost.install(
at org.apache.catalina.startup.HostConfig.deployApps(
at org.apache.catalina.startup.HostConfig.start(
at org.apache.catalina.startup.HostConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
at org.apache.catalina.core.ContainerBase.start(

at org.apache.catalina.core.StandardHost.start(
at org.apache.catalina.core.ContainerBase.start(

at org.apache.catalina.core.StandardEngine.start(
at org.apache.catalina.core.StandardService.start(
at org.apache.catalina.core.StandardServer.start(
at org.apache.catalina.startup.Catalina.start(
at org.apache.catalina.startup.Catalina.execute(
at org.apache.catalina.startup.Catalina.process(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
at java.lang.reflect.Method.invoke(
at org.apache.catalina.startup.Bootstrap.main(
Starting service Tomcat-Apache
Apache Tomcat/4.0.4

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"

my sturts-config.xml file is
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName" value="sun.jdbc.odbc.JdbcOdbcDriver"/>
<set-property property="url" value="jdbc dbc:StrutsData"/>
<form-bean name="loginForm" type="LoginForm"/>






<action path="/login" type="LoginAction" scope="request" name="loginForm" input="/WebPage/Login.jsp">
<forward name="success" path="/WebPage/Success.html" redirect="true"/>
<forward name="failure" path="/WebPage/Failure.html" redirect="true"/>



<message-resources parameter="BankingMessageResources" null="false"/>

my Action class is

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.*;
import javax.sql.*;
public class LoginAction extends Action {
DataSource datasource = null;
Connection connection = null;
Statement statement = null;
int i=0;

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {

LoginForm lf = (LoginForm)form;
String username = lf.getUsername();
String password1 = lf.getPassword1();
String password2 = lf.getPassword2();
String query = "insert into tbluser(username,password1,password2) values('"+username+"','"+password1+"','"+password2+"')";
if(password1.equals(password2)) {
try {
//connection = DriverManager.getConnection("jdbc dbc:StrutsData");
datasource = getDataSource(request);
connection = datasource.getConnection();
}catch(Exception e) {
System.out.println("Error in Driver Connection");
try {
statement = connection.createStatement();
i = statement.executeUpdate(query);
System.out.println("Query Executed i= "+i);
return mapping.findForward("success");

}catch(Exception e) {

return mapping.findForward("failure");
return mapping.findForward("failure");

Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Struts DataSource utility has been deprecated, so you simply won't find the getDataSource method in the Action class any more. That's why you're getting the error.

For some information on what to use instead, see question 7 of the Javaranch Struts FAQ
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic