DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    1

    <identifier> error message

    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;
    }
    }

  2. #2
    Join Date
    Oct 2005
    Posts
    107
    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";
    }

    I just don't see the point of this method??

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links