Struts and database connection
I am new in Struts and I need help to connect to mysql database. The problem is: The requested resource (Servlet action is not available) is not available.
here is my <data-source> in struts-config.xml :
<data-sources>
<data-source type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<set-property
property="driverClassName"
value="com.mysql.jdbc.Driver" />
<set-property
property="url"
value="jdbc:mysql://localhost:3306/casopisi?autoReconnect=true" />
<set-property
property="username"
value="root" />
<set-property
property="password"
value="root" />
<set-property
property="maxActive"
value="10" />
<set-property
property="maxWait"
value="5000" />
<set-property
property="defaultAutoCommit"
value="false" />
<set-property
property="defaultReadOnly"
value="false" />
<set-property
property="validationQuery"
value="SELECT COUNT(*) FROM test" />
</data-source>
</data-sources>
is the problem in this or in action class?
public class LogIn extends Action {
private final static String SUCCESS = "success";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
javax.sql.DataSource dataSource = null;
java.sql.Connection myConnection;
String username = request.getParameter("username");
String password = request.getParameter("password");
try{
ServletContext context = servlet.getServletContext();
DataSource datasource;
myConnection = dataSource.getConnection();
PreparedStatement stmt=(PreparedStatement) myConnection.createStatement();
String query ="SELECT username, password from users where username=? and password=?";
ResultSet RS=stmt.executeQuery(query);
while(RS.next()){
UserActionFormBean UserBean = (UserActionFormBean)form;
UserBean.setUsername(RS.getString("username"));
UserBean.setPassword(RS.getString("password"));
if(UserBean.getUsername().equals(username)){
return mapping.findForward("logedin");
}
}
}catch (SQLException sqle) {
getServlet().log("Connection.process", sqle);
}
return mapping.findForward("fail");
}
}

