Hello Rancher's ,
I am facing an invalid cursor state error when i enter Login Id and Password which is not in database
means in the below code ... else loop is not working ..... If the login id and password is correct then it is working fine (if loop is working fine).
import java.io.*;
//import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Reg1LoginServlet extends HttpServlet
{
//Hashtable users = new Hashtable();
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
doPost(req, res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
PrintWriter out=res.getWriter();
String Login=req.getParameter("member_login");
String Password=req.getParameter("member_password");
Connection con = null;
ResultSet rs = null;
PreparedStatement stmt = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc

dbc:RohitDB1");
PreparedStatement stat=con.prepareStatement("select * from RegInfo where Login=? and Password=?");
stat.setString(1,Login);
stat.setString(2,Password);
rs=stat.executeQuery();
if ( Login != null && Password != null && rs!= null)
{
rs.next();
req.setAttribute("Login", rs.getString("Login"));
req.setAttribute("Password", rs.getString("Password"));
req.setAttribute("First_name", rs.getString("First_name"));
req.setAttribute("Last_name", rs.getString("Last_name"));
req.setAttribute("Email", rs.getString("Email"));
req.setAttribute("Country", rs.getString("Country"));
req.setAttribute("City", rs.getString("City"));
req.setAttribute("Zip", rs.getString("Zip"));
req.setAttribute("Address", rs.getString("Address"));
req.setAttribute("Phone", rs.getString("Phone"));
ServletContext ct = getServletContext();
RequestDispatcher rd = ct.getRequestDispatcher("/LoginInfo.jsp");
rd.forward(req, res);
return;
}
else{
out.println("<h4><div align ='center'>Login Details Entered By You Are Not Correct, Please Try Again</h4></div>");
RequestDispatcher rd = req.getRequestDispatcher("/RND/Reg1Login.jsp");
rd.include(req, res);
return;
}
}
catch(Exception E)
{
out.println("Error"+E);
}
out.close();
}
}
please help at your earliest.
YOgi.