Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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:

    <&#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
    Last edited by guravharhsa; 07-10-2008 at 03:43 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    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

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    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
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •