Zero resultset for MYSQL despite data in tables

I'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.

[2419 byte] By [MamaPandaa] at [2007-11-27 6:14:34]
# 1

The current row index is always 0 if you don't move the cursor using ResultSet#next().

Two small things I would to mention: this can also be done in just one query instead of two. And rather use PreparedStatement instead of Statement as it look like that you're not doing any SQL injection checks.

BalusCa at 2007-7-12 17:24:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Oh my god... I really forgotten abt it..

I kept thinking the problem was elsewhere and never paid attention to it. Kept thinking there was something wrong with my deployment or my queries. Thanks so much. I've changed all to prepared statements already.

Rather embarrassing mistake..

Thanks BalusC :)

MamaPandaa at 2007-7-12 17:24:12 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...