Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Oct 11th, 2006, 1: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
Old Oct 11th, 2006, 1:25 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
It would seem as if your application cannot find the class "com.mysql.jdbc.Driver". Is the MySQL jar in your web apps classpath?
Arevos is offline   Reply With Quote
Old Oct 11th, 2006, 1:33 PM   #3
C41R0
Newbie
 
Join Date: Oct 2006
Posts: 3
Rep Power: 0 C41R0 is on a distinguished road


yup
C41R0 is offline   Reply With Quote
Old Oct 11th, 2006, 2:10 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Oct 12th, 2006, 12:09 AM   #5
C41R0
Newbie
 
Join Date: Oct 2006
Posts: 3
Rep Power: 0 C41R0 is on a distinguished road
yeah.. you're right, after i move one level up of my directory, the problem solved
thanks a lot
C41R0 is offline   Reply With Quote
Reply

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 9:01 AM




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

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