Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
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
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cant connect servlet to MySQL DB BizzyC Java 0 Mar 8th, 2005 10:01 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:21 AM.

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