![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 3
Rep Power: 0
![]() |
[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 |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
It would seem as if your application cannot find the class "com.mysql.jdbc.Driver". Is the MySQL jar in your web apps classpath?
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 3
Rep Power: 0
![]() |
![]() yup |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2006
Posts: 3
Rep Power: 0
![]() |
yeah.. you're right, after i move one level up of my directory, the problem solved
thanks a lot |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Cant connect servlet to MySQL DB | BizzyC | Java | 0 | Mar 8th, 2005 9:01 AM |