I was trying to connect LoginServlet to the database that I have built.
The connection driver, etc was handled in DatabaseConnection.java
And I try to access one of the function in it through LoginServlet.java
However, when I tried to compile LoginServlet.java, (the code is attached below)
The compiler cannot identify DatabaseConnection
"cannot find symbol"
"variable: DatabaseConnection"

When I tried to move the line "DatabaseConnection.connect()" into a line above the doPost method, the error was now become "<identifier> expected"

Can someone please help me find the bug?
Thanx a lot..


//LoginServlet.java

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String userName = request.getParameter("username");
String password = request.getParameter("password");
String query="SELECT COUNT(username) from member where username='" + userName + "'";
String url="";
DatabaseConnection.connection();
ResultSet rs = DatabaseConnection.getQueryResults(query);

while(rs.next())
{
int numOfMember = Integer.parseInt((rs.getString(1)).trim());
if(numOfMember == 0) returnMessage("Username does not exist");
else if (numOfMember!=0)
{
query="SELECT password FROM member WHERE username=";
rs = DatabaseConnection.getQueryResults(query + userName);
while(rs.next())
{
String tempPass = rs.getString(1);
if(tempPass.equals(password)) returnMessage("Login success");
else
returnMessage("Wrong password");
}
}
}
}

public String returnMessage(String status)
{
if(status.equals("Username does not exist")) return "Username not exist";
else if(status.equals("Wrong password")) return "Wrong password";
else if(status.equals("Login success")) return "Login Success";
}
};


//DatabaseConnection.java
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class DatabaseConnection// extends HttpServlet
{
private static final String dbname = "auction";
private static final String dbuser = "root";
private static final String dbpwd = "";

private static Connection conn = null;
private static Statement stmt = null;

public static void connection()
{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + dbname, dbuser, dbpwd);
}
catch (Exception ex){
ex.printStackTrace();
}
}

public static ResultSet getQueryResults(String query){
try{
return stmt.executeQuery(query);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}