Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    2

    Unanswered: Problem trying to execute query

    I have a class created specially for mysql DB connection (DBUtil.java) and i have a servlet (LoginServlet.java) for login and it is where the query is to be execute. But sadly, it gives me error "NullpointerException" (Error.gif) and point to the line of code "PreparedStatement ps = conn.prepareStatement(sql);"

    And now i dunno what's wrong, can someone help?

    1) I'm not sure if i using the correct driver and url for my DB, but i tested it before and it connected. Check out DBUtil.java
    2) Don't know if there is/are anything wrong with the codes, refer to LoginServlet.java

    All required information are in the attachment (Resources.zip)

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    There is probably something wrong with your connection object. Try throwing some debugging output to make sure that conn is actually being set correctly to what you want. Chances are it's either being initialized incorrectly or to a null/empty object.

    Also won't this shutdown/stop the mysql server? I'd assume the program can't create a connection if the database isn't running...
    Code:
        public static void closeConnection()
        {
            try
            {
               Statement st = conn.createStatement();
               st.execute("SHUTDOWN");
               conn.close();
            }
            catch (SQLException se)
            {
                  se.printStackTrace();
            }
        }

  3. #3
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Also check the tomcat logs...there's usually more useful info in there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •