I'm working on a web application for a class of mine. The assignment is to create a College Services app where students can login and register for classes. Right now I'm working on the login portion and it coded out but I'm having some issue and hopeing I get a little help.
After running the debugger in netbeans, I've noticed that is breaking at the
connection = DriverManager.getConnection(dburl, login, pass);
of the ConnectionManager.java.
I was wondering if someone could take a look at my code and see if they can see anything I'm doing wrong.
LoginServlet.java
package login;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import business.*;
import data.*;
public class LoginServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String userId = request.getParameter("userId");
String password = request.getParameter("password");
HttpSession session = request.getSession();
User user = new User();
user.setUserId(userId);
user.setUserPass(password);
user = LoginValidate.validate(user);
if(user.isSuccessful())
{
session.setAttribute("user", user);
String url = "/studenthome.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
else if(!user.isSuccessful())
{
response.sendRedirect("index.jsp");
}
}
/*protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
this.doGet(request, response);
}*/
}
LoginValidate.java
package data;
import java.sql.*;
import business.*;
public class LoginValidate
{
public static User validate(User user)
{
String u = user.getUserId();
String p = user.getUserPass();
String query = "select * from students where StudentId='" + u + "' AND StudentPass='" + p +"'";
try
{
Connection connection = ConnectionManager.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
String rsUser = resultSet.getString(0);
String rsPass = resultSet.getString(1);
//boolean userExist = resultSet.next();
if(u.equals(rsUser) && p.equals(rsPass))
{
String fName = resultSet.getString("FirstName");
String lName = resultSet.getString("LastName");
user.setUserFName(fName);
user.setUserLName(lName);
user.setSuccessful(true);
}
else
{
user.setSuccessful(false);
}
}
catch(Exception e)
{
}
return user;
}
}
ConnectionManager.java
package data;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionManager
{
static Connection connection;
public static Connection getConnection()
{
try
{
String dburl = "jdbc:mysql://localhost:3306/collegeservices";
String login = "root";
String pass = "root";
connection = DriverManager.getConnection(dburl, login, pass);
}//end try
catch(SQLException sqle)
{
for(Throwable t : sqle){
t.printStackTrace();
}
}//end catch
return connection;
}//end getConnection()
}
I've been stuck on this and can't seem to see what's wrong. WHen it gets to taht connection = DriverManager.getConnection(dburl, login, pass) it drops down to the catch block.
Any insight to fixing this problem is greatly appreciated
thanks
jay