i have problem in connecting database through struts as i am relevently new to it. i wanted to test it with my MS Access but it gave this error
<Jun 3, 2003 5:54:26 PM IST> <Error> <HTTP> <[WebAppServletContext(5856205,Defau
ltWebApp,/DefaultWebApp)] Servlet failed with Exception
java.lang.NullPointerException
at org.struts.example.StrutsInputAction.perform(StrutsInputAction.java:5
9)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionSer
vlet.java:1787)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:158
6)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:262)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:198)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:2637)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2359)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
how to write data sources tag in struts-config.xml? if possible give me some sample coding for connecting database.
thanks in advance
-
how to connect the database using struts (4 messages)
- Posted by: Dinagar Venkatesan
- Posted on: June 03 2003 08:23 EDT
Threaded Messages (4)
- Add another layer, for starters by SAF . on June 03 2003 09:37 EDT
- how to connect the database using struts by Kiran Kumar on June 03 2003 13:48 EDT
- how to connect the database using struts by Pratap Das on June 03 2003 18:35 EDT
- Here You go by Zeeshan Haider on June 04 2003 05:51 EDT
-
Add another layer, for starters[ Go to top ]
- Posted by: SAF .
- Posted on: June 03 2003 09:37 EDT
- in response to Dinagar Venkatesan
I would avoid connecting directly to a database from a web component, such as a servlet. If I were you, I would, at least, design a data access layer using DAO objects that can connect, read, and write to a database. With this type of design you can encapsulate all of your query and persistence logic in a separate layer, which facilitates future changes, which will no doubt be required as the application matures.
I've never used Struts, sorry I could not help on that :-P
SAF -
how to connect the database using struts[ Go to top ]
- Posted by: Kiran Kumar
- Posted on: June 03 2003 13:48 EDT
- in response to Dinagar Venkatesan
could you please specify which component of struts (Action,ActionForm,jsp) is trying to connect to the DB ?
If it is from Action classes, then I believe it should be no different from any other servlet (either direct JDBC(not recommended), or DAO(recommended) )
However, if it is from JSP to get some properties from Database, then you might want to write a custom tag lib for that.
Thanks -
how to connect the database using struts[ Go to top ]
- Posted by: Pratap Das
- Posted on: June 03 2003 18:35 EDT
- in response to Dinagar Venkatesan
i have problem in connecting database through struts as i am relevently new to it. i wanted to test it with my MS Access but it gave this error
>
> <Jun 3, 2003 5:54:26 PM IST> <Error> <HTTP> <[WebAppServletContext(5856205,Defau
> ltWebApp,/DefaultWebApp)] Servlet failed with Exception
> java.lang.NullPointerException
> at org.struts.example.StrutsInputAction.perform
It is giving a NullPointer in the perform method. See what's being done there.
<snip>
> how to write data sources tag in struts-config.xml? if possible give me some sample coding for connecting database.
Look here for an example:
http://javaboutique.internet.com/Web_App_Struts/index-2.html
--Das -
Here You go[ Go to top ]
- Posted by: Zeeshan Haider
- Posted on: June 04 2003 05:51 EDT
- in response to Pratap Das
Hi using jdbc pool of commons with struts frame work is good but not 2 good to use you may get lot of other choices the one i am using you can get from http://www.richardsonpublications.com/dbpool/index.jsp where you found all the detail to use it, then you don't need to specify datasource property in sturts-config.xml cause you are using thrid party connection pool.
Apart from this doing jdbc in struts is as easy you use to from simple java class in struts you should connect to database from your Bean class not FormBean i am talking about the helper Bean class where you perform all the business logic the benfit of this is that you can also use this bean class any where else as it is.
then you can call your methods from Action Class and do all the stuff you want.
regards...
Zeeshan Haider