File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes invalid cursor state Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "invalid cursor state" Watch "invalid cursor state" New topic
Author

invalid cursor state

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
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.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
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:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invalid cursor state