import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.lang.NullPointerException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
*
* @author Animesh Pandey
*/
public class anilet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection conn = null;
String username = null;
String userpass = null;
String strQuery = null;
Statement st = null;
ResultSet rs = null;
HttpSession session = request.getSession(true);
try {
out.println("I am here!1"); //gets printed
[B][U][I]Class.forName("com.mysql.jdbc.Driver");[/I][/U][/B]
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/usermaster","root","");
out.println("I am here!2"); // Does not ger printed
if(request.getParameter("username") != null && request.getParameter("password") != null)
{
username = request.getParameter("username").toString();
userpass = request.getParameter("password").toString();
out.println(username);
out.println(userpass);
strQuery = "select * from usermaster where username='" + username + "' and password='" + userpass + "'";
System.out.println(strQuery);
st = conn.createStatement();
rs = st.executeQuery(strQuery);
int count=0;
while(rs.next()){
session.setAttribute("username",rs.getString(2));
count++;
}
out.println(count);
if(count>0){
response.sendRedirect("welcome.jsp");
}
else{
response.sendRedirect("login.jsp");
}
}
else{
response.sendRedirect("login.jsp");
}
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
}
catch(Exception e) {
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
This servlet does not run after the "Class.forName("com.mysql.jdbc.Driver");", I mean to say that any code after this command does not run ... but it also does not give any error. The project also builds successfully. What could be the problem ????
:confused: :?:
Please help!