connectivity problem
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.sql.*;
public class TestDataSource extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
javax.sql.DataSource dataSource;
java.sql.Connection myConnection=null;
try {
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
Statement stmt=myConnection.createStatement();
ResultSet rst=stmt.executeQuery("select username from test");
System.out.println("******************************************");
System.out.println("********Out Put from TestDataSource ******");
while(rst.next()){
System.out.println("User Name is: " + rst.getString("username"));
}
System.out.println("******************************************");
rst.close();
stmt.close();
// do what you wish with myConnection
} catch (SQLException sqle) {
getServlet().log("Connection.process", sqle);
} finally {
//enclose this in a finally block to make
//sure the connection is closed
try {
myConnection.close();
} catch (SQLException e) {
getServlet().log("Connection.close", e);
}
}
return mapping.findForward("success");
}
}
this is the connectivity program of strut with MYSQL. it gives error while
compiling the program. i set strut.jar, servlet.jar. mysqlconnector.jar file before compiling.
it gives this type error.
TestDataSource.java:23: cannot resolve symbol
symbol : method getDataSource (javax.servlet.http.HttpServletRequest)
location: class TestDataSource
dataSource = getDataSource(request);
^
1 error
pls solve my problem

