View Single Post
Old Oct 11th, 2006, 2:16 PM   #1
C41R0
Newbie
 
Join Date: Oct 2006
Posts: 3
Rep Power: 0 C41R0 is on a distinguished road
[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
C41R0 is offline   Reply With Quote