error:javax.servlet.ServletException: java.sql.SQLException: Illegal operation on emp

--------------------------------------------------------------------------------

Hi,
I am stuck here about 2-hours. Kindly help me.
In this my updateuser.jsp page I am retrieving the data from drop down list which is in my search user.jsp . I am taking form name of searchuser.jsp page for reference here which is form1. in my user table there is column userid, emailed, password:
Now here I am trying to display the data about the user selected from drop down list in searchuser.jsp
Here is an my updateuser.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language ="java" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String form=request.getParameter("form1");//name of previous drop down list menu

InitialContext context = new InitialContext(); 
DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mynewdatabase"); 
Connection conn = ds.getConnection(); 
context.close();

Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select emailid,password from user where emailid='"+form+"'");
rs.next();
[B]String EMAIL = rs.getString("emailid");[/B]
String PASSWORD = rs.getString("password");
rs.close();
%>
<table border="1">
<thead>
<tr>
<th><b>MODIFY USER</b></th>
</tr>
</thead>
<tbody>
<tr>
<td>E-MAIL</td>
<td><input type="text" name="email" value="<%=rs.getString("EMAIL")%>" size="30" /> </td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="text" name="password" value="<%=rs.getString("PASSWORD")%>" /></td>
</tr>
<tr>
<td><input type="submit" value="SUBMIT" name="submit" /></td>
<td><input type="reset" value="RESET" name="res" /></td>
</tr>
</tbody>
</table>


</body>
</html>

But the error shows at marked line as:
javax.servlet.ServletException: java.sql.SQLException: Illegal operation on empty result set.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)

Whether I am trying in the right way?
Any suggestion is highly appreciated
Thanks and Regards
Haresh

javax.servlet.ServletException: java.sql.SQLException: Illegal operation on empty result set.

Honestly I do not know why would you choose not to believe your Web Server when in fact it has practically pin pointed the root cause of the error to you, the above line clearly states the ResultSet generated from your query was empty and hence the getString() method which you are calling on it is throwing this Exception. You can check for an empty ResultSet with the first call of rs.next() , it returns false on the first call if and only if the ResultSet generated was empty(that is cause, next() tells you whether there are any more records after the current position on the cursor and initially the cursor is positioned before the first row in the ResultSet ) which is your case, but you have chosen to ignore it.
And I also am pretty sure you have been already informed many times that it is **NOT ADVISABLE** to do your database activity inside a JSP page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.