dcsimg
getDataSource(request) is undefined in my action class
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sneha_rao
Posted On:   Thursday, November 9, 2006 10:06 PM

Hi, I am new to struts and trying to connect to mysql database. i have configured datasource in struts-config.xml. i cannot use getDataSource(request) in my action class. it will show error if i use this method in my action class here is the code public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ //database connection. UserRegistrationForm userform = (UserRegistrationForm)form; try{ datasource = getDataSource(request); Connection conn = datasource.getConnection();    More>>

Hi,


I am new to struts and trying to connect to mysql database.
i have configured datasource in struts-config.xml.
i cannot use getDataSource(request) in my action class. it will show error if i use this method in my action class



here is the code




public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) throws Exception{




//database connection.

UserRegistrationForm userform = (UserRegistrationForm)form;


try{


datasource = getDataSource(request);


Connection conn = datasource.getConnection();




PreparedStatement stmt = datasource.getConnection).prepareStatement("insert into USER" +
"(EMAIL,FIRST_NAME, LAST_NAME, PASSWORD, PHONE, FAX)"+
"VALUES('aaa','bbb','ccc','ddd','1111','333')");




stmt.setString(1,userform.getEmail());


stmt.setString(2, userform.getFirstName());


stmt.setString(3,userform.getLastName());


stmt.setString(4,userform.getPassword());


stmt.setString(5,userform.getPhone());


stmt.setString(6,userform.getFax());


}
catch (SQLException e){


getServlet().log("connection.process",e);


}
finally{
try{
datasource.getConnection().close();


}
catch(SQLException ex){
getServlet().log

("connection.close",ex);




}
}
log.trace("In execute method of UserRegistrationAction");


return mapping.findForward("success");

   <<Less
About | Sitemap | Contact