- This topic has 1 reply, 2 voices, and was last updated 17 years, 8 months ago by Riyad Kalla.
-
AuthorPosts
-
nagoMemberHi,
I am new for Struts application. While i connect my application to database it works fine while i write
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
connection = DriverManager.getConnection(“jdbc:odbc:StrutsData”);code – while i am using data source tag struts-config.xml file, it display following error and i have one more error in my Actionclass line datasource=getDataSource(request), any body please help me
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<!DOCTYPE struts-config PUBLIC
“-//Apache Software Foundation//DTD Struts Configuration 1.1//EN”
“http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd”><struts-config>
<data-sources>
<data-source type=”org.apache.commons.dbcp.BasicDataSource”>
<set-property property=”driverClassName” value=”sun.jdbc.odbc.JdbcOdbcDriver”/>
<set-property property=”url” value=”jdbc:odbc:StrutsData”/>
</data-source>
</data-sources>
<form-beans>
<form-bean name=”loginForm” type=”LoginForm”/>
</form-beans><global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<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”/>
</action></action-mappings>
<controller
contentType=”text/html;charset=UTF-8″
debug=”3″
locale=”true”
nocache=”true”/><message-resources parameter=”MessageResources” null=”false”/>
</struts-config>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 {
//Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
//connection = DriverManager.getConnection(“jdbc:odbc:StrutsData”);
datasource = getDataSource();
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”);
}}
May 30, 2007 2:33:51 PM org.apache.struts.action.ActionServlet initApplicationDa
taSources
SEVERE: Initializing application data source org.apache.struts.action.DATA_SOURC
E
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1406)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1254)
at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.jav
a:191)
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.
java:217)
at org.apache.struts.action.ActionServlet.initApplicationDataSources(Act
ionServlet.java:911)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:446)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.
java:918)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:81
0)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContex
t.java:3279)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3
421)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:78
5)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:478)at org.apache.catalina.core.StandardHost.install(StandardHost.java:738)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:300
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:389)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:232)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:155)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1131)at org.apache.catalina.core.StandardHost.start(StandardHost.java:638)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1123)at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:343
)
at org.apache.catalina.core.StandardService.start(StandardService.java:3
88)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:506
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:781)
at org.apache.catalina.startup.Catalina.execute(Catalina.java:681)
at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:243)
Riyad KallaMemberMoving to OT > Soft Dev
-
AuthorPosts