Zero resultset for MYSQL despite data in tables
843859Jun 2 2007 — edited Jun 3 2007I've been getting zero for all my query result sets even though my database is not empty. I don't know if the problem lies with my servlet code or my resin deployment. Can someone tell me what's wrong?
Here's part of the codes.
Login.java
public class Login extends HttpServlet {
final String LOGIN_HOME = "/login.jsp";
final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
final String JDBC_URL = "jdbc:mysql://localhost/algebar";
String errorMsg = "";
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String loginId = request.getParameter("loginId");
String password = request.getParameter("password");
if (loginId != null && password != null)
try {
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(JDBC_URL,"root","algebar");
Statement stmt = conn.createStatement();
ResultSet r = stmt.executeQuery("Show databases");
System.out.println("number rows="+r.getRow());
String nextPage = this.LOGIN_HOME;
byte loginType = validateUser(loginId,password,conn);
--- snipped --
private byte validateUser(String loginId, String password, Connection conn)
throws SQLException {
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery(
"select login_type from login where login_id = '"+loginId+
"' AND password='"+password+"'");
if (results.getRow()==0) {
String query = "select * from login where login_id = '"+loginId+"'";
results = stmt.executeQuery(query);
if (results.getRow()==0) {
System.out.println(query);
setMessage("Invalid user name.");
}
else setMessage("Invalid password.");
return 0;
}
else {
return results.getByte("login_type");
}
}
Did I miss out something in my web.xml ? I'm currently using Netbeans5.5 but I have trouble deploying this servlet to test it with the pre-installed Tomcat5.5 . I have Tomcat6.0 and Apache 2.2 as well but I'm also having trouble starting TOmcat6.0 so that's why I'm using Resin3.11. I have no problems accessing login.jsp and the Login servlet but the executeQuery() all return zero ResultSet .
Hope someone can give me an idea of what I'm missing or have done wrong.