...

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



guravharhsa
07-10-2008, 02:02 PM
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:

<&#37;@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();
String EMAIL = rs.getString("emailid");
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

BubikolRamios
07-10-2008, 05:45 PM
as it says , no records.

replace sql with: select count(emailid) as count1 from user where emailid ...
rs.next();
String EMAIL = rs.getString("count1");
almost sure email will be 0

guravharhsa
07-11-2008, 09:30 AM
Hi,
I updated it. now it shows like below
In the below jsp page, i am retrieving the data from drop down list of adduser.jsp page .but showing the error like:
javax.servlet.ServletException: java.sql.SQLException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
The error showing is at marked line.
Here is an code:


<%@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>
<table border="1">
<%
String form=request.getParameter("form1");
Connection connection = null;
Statement st = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mynewdatabase","root", "root123");
st=con.createStatement();
try {
rs = st.executeQuery("select emailid,password from user where emailid='"+form+"'");
String EMAIL = rs.getString("emailid");
String PASSWORD = rs.getString("password");
while (rs.next())
{
%>

<tbody>
<tr><thead>
<tr>
<th><b>MODIFY USER</b></th>
</tr>
</thead>
<td>E-MAIL</td>
<td><input type="text" name="email" value="<%=rs.getString("userid")%>" ><%=rs.getString("EMAIL")%> size="30" /> </td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="text" name="password" value="<%=rs.getString("userid")%>" ><%=rs.getString("PASSWORD")%> size="10" /></td>
</tr>
<tr>
<td><input type="submit" value="SUBMIT" name="submit" /></td>
<td><input type="reset" value="RESET" name="res" /></td>
</tr>
</tbody>
<%
}
}
finally
{
if (rs != null)
{
rs.close();
rs = null;
}
if (st != null)
{
st.close();
st = null;
}

}
%>


%>
</table>
</body>
</html>
Thanks for any Suggestion
Regards
haresh

shyam
07-11-2008, 05:58 PM
you gotta call rs.next() before you can start reading information off the resultset. and, make sure u check the return of the next() method which will return false if no records were fetched



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum