I have developed registration and login form using jsp and servlets.
Now I am trying to retrieve data from database which i have inserted using registration page.
Once I login I will have a link for profile where it should display the details of that user.
This lot should not be in a JSP.
You should have a servlet that gets the data you need to display and then forwards to the JSP.
If nothing else it makes it a lot easier to debug any issues.
What line of code is that error being thrown from (this is one case, for example, where it would be easier as a servlet)...
In this case, though, I can se the issue.
You are trying to read data from the ResultSet before you have called rs.next(), hence the "before start of result set" error.
One suggestion (apart from the "move to a servlet" one). You should query the database to return only the entry you want, rather than all the entries in the table and then try and find the one that matches.
SELECT * FROM registration WHERE user_name = ? and password = ?
I would also not return the password unless you really want it. And if you did really want it then I would sit down for a while until that desire went away.
The code has some issues, though: you should not put Java code in JSPs, and you should definitely not store passwords in cleartext in the DB. But start with getting the basic code to run, and then bring it in line with common software practices.
Thank you so much..
That issue is resolved. but I am stuck with another issue. As you said I have written the whole code into a servlet.
Actually when I login into a page I have a link profile.. when I click it I should get the data of that user. Now I am getting a null pointer exception. Please help me out!
You don't want to be printing anything to the response writer in that code.
You want to create a User class, and then create an instance of it that you can put all the data you need into it.
After you have that class, you then want to add it to the request.
Finally you want to forward to your JSP page.
Inside your JSP you can then use EL notation and JSTL tags to access that data.
However...that query is incorrect.
You are not setting values for name or password.
There should be a couple of setString calls on the PreparedStatement to set the values to search on, before calling executeQuery.
And then you should be able to simply:
That while loop is not necessary as you should only get one row back at mos (if the user_name and password are correct).
You can also forgot the if check, as the query has already done that for you.
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss