having an error with the log in from html/jsp to servlet accessing database..
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.DemoLogin.LoginServlet.service(LoginServlet.java:55)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
it says at line 55 tried to debug it but it still doesnt work here is my code
public class LoginServlet extends HttpServlet {
Connection con;
String user;
String pass;
@Override
public void init(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql:127.0.0.1","admin","");
}catch(ClassNotFoundException | SQLException e){
System.out.println("Error while loading connection"+ e);
}
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
PrintWriter out = response.getWriter();
try{
user=request.getParameter("uname");
pass=request.getParameter("pwd");
String q="select * from employee where empname='"+user+"'";
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(q);
String username=null;
String password=null;
while(rs.next()){
username=rs.getString(2);
password=rs.getString(3);
}
Line 55 contains the block of Statement st = con.createStatement() no errors with the codes yet I have no idea what the problem is
As you can see I took a reference from youtube and made some adjustments a lot of videos in youtube doesnt show a working sample for netbeans + wamp/ampache tomcat tutorials so I decide to ask for help here, hope someone can help me I'm making a Web Application for my thesis