• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

invalid cursor state

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not that this has anythingto do with servlets per-se, but yes that will happen. If you check the javadoc for the ResultSet class, you'll see that the next() method returns a boolean to indicate if the new current row is valid or not. You are just ignoring that, and going on to read data irrespective.

try something like the following:

reply
    Bookmark Topic Watch Topic
  • New Topic