I got a jsp page which forwards request of two textfields txtname and txtpass to a servlet and the servlet then inserts the data into sql db and the name of the db is online_store. The db has two columns. When i checked the values are passing to the servlet post method But for some reason am getting null pointer exception. Help me out
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String name= request.getParameter("txtname");
String pass= request.getParameter("txtpass");
Connection connection=null;
ResultSet rs;
if(name !=null && pass!=null)
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connectionurl= "jdbc:sqlserver://MITH-PC; database=Online_Store; user=sa; password=mith1234";
String sql="Insert into login values(?,?)";
PreparedStatement pstmt= connection.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, pass);
int no= pstmt.executeUpdate();
pstmt.close();
}
catch(ClassNotFoundException e){
out.println("problem with the driver: " + e.getMessage());
}
catch(SQLException e){
out.println("SQLException caught: " + e.getMessage());
}
catch (Exception e){
out.println(e);
}
}