Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   [java] servlet and mysql problem (http://www.programmingforums.org/showthread.php?t=11545)

C41R0 Oct 11th, 2006 2:16 PM

[java] servlet and mysql problem
 
:


 package coreservlets;

  import java.sql.*;
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import coreservlets.beans.*;
 
    public class Database extends HttpServlet
  {
      public void doGet(HttpServletRequest apply,
                                                      HttpServletResponse react)
                                              throws ServletException, IOException
      {
     
        react.setContentType("text/html");
        HttpSession session=apply.getSession();
        String ID=(String)session.getAttribute("ID");
        ID=null;
        String userPassword=null;
        String basePassword=null;
        String pass="";
        String title="";
        String userName = "root";
        String password = "root";
        Connection connection=null;
        try
        {
            int wrongID = 0;
            if (ID == null)
            {
              ID=apply.getParameter("ID");
              userPassword=apply.getParameter("userPassword");
              System.out.println("userPassword"+userPassword);
            }
            System.out.println("start sql");
       
            String url = "jdbc:mysql://localhost:3306/sit";
            Class.forName ("com.mysql.jdbc.Driver"); 
            connection= DriverManager.getConnection (url, userName, password);
            Statement stmt= connection.createStatement();
            ResultSet query =stmt.executeQuery("SELECT password from validation WHERE students='"+
                                      ID +"'" );
            System.out.println("query.next,,"+query);
           
               
            while(query.next())
            {
              pass=query.getString("password");
              System.out.println("pass>>"+pass);
            }
            if (userPassword.equals(pass))
            {
              System.out.println("password is true!");
            }
        } 
            catch (ClassNotFoundException cnfe)
            {
              System.out.println("class not found");
            }
            catch (SQLException e)
            {
              System.out.println("query failed");
            }
        finally
        {
            try
            {
              connection.close();
            }
                catch(Exception e)
              {
                  System.out.println("closing failed");
              }
        }
      }
      public void doPost(HttpServletRequest apply,
                        HttpServletResponse react)
      throws ServletException, IOException {
        doGet(apply, react);
      }
 
     
  }


The output i got are "class not found" and "closing failed".
why ? i made any mistake here ?
kindly appreciate if someone can tell me

Arevos Oct 11th, 2006 2:25 PM

It would seem as if your application cannot find the class "com.mysql.jdbc.Driver". Is the MySQL jar in your web apps classpath?

C41R0 Oct 11th, 2006 2:33 PM

http://i20.photobucket.com/albums/b2...untitled-3.jpg

yup

Arevos Oct 11th, 2006 3:10 PM

You could try moving the JAR file up one directory level.

Edit Also, it might help if you called the printStackTrace() method on the exception being thrown. Then we'd have a more descriptive error message.

C41R0 Oct 12th, 2006 1:09 AM

yeah.. you're right, after i move one level up of my directory, the problem solved
thanks a lot


All times are GMT -5. The time now is 1:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC