Error: ResultSet was not produced

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tejasvee1234
    New Member
    • May 2013
    • 1

    Error: ResultSet was not produced

    This is the code I'm using to isert record in SQL but it produced the "ResultSet error not produced" and even it did not inserted the mobile field, but the field is set to "not null" still it was showing null.
    Code:
    <%	
            try
    	{
                String n=request.getParameter("name");
                String u=request.getParameter("uname");
                String p=request.getParameter("pwd");
                String y=request.getParameter("Year");
                String g=request.getParameter("Gender");
                String e=request.getParameter("EmailID");
                String c=request.getParameter("Moblie");
                String a=request.getParameter("Address");
    	Connection con=DriverManager.getConnection("jdbc:odbc:uinfo; uid=System; pwd=tandon");
    			Statement st=con.createStatement();
    			ResultSet rs=st.executeQuery("insert into uinfo values('"+n+"','"+u+"','"+p+"','"+y+"','"+g+"','"+e+"','"+c+"','"+a+"');");
    		     if(rs.next())
                         {
                            %> <jsp:forward page="U_Login.jsp" /> <%
                         }
                else
                    {
                    out.println("please retry");
              %><br><br> <a href="http://bytes.com/SignUp.jsp">Back to Home</a> <%
                       }         
      con.close();
            
             }               
            catch(Exception e)
             {
             out.println(e);
             }
            %>
    Last edited by acoder; May 24 '13, 08:02 PM. Reason: Please use [code] tags when posting code
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    tejasvee1234,

    If I remember correctly, when the executeQuery() method works on an INSERT statement, it doesn't produce a result set, as there are no values generated. Try using the execute() method, instead.

    The first thing to do is see if your SQL is correctly formed; usually done by printing it out. Then once the SQL is correct, then you can do the insert.

    Judging from your comment, though, you need to use the execute() method, and check the boolean result, instead.

    Luck,
    Oralloy

    Comment

    • PreethiGowri
      New Member
      • Oct 2012
      • 126

      #3
      ExecuteUpdate has to be used instead of ExecuteQuery for insert, update and delete queries. Write something like,

      Code:
       Statement st=con.createStatement();
                  int rs=st.executeUpdate("insert into uinfo values('"+n+"',
      '"+u+"','"+p+"','"+y+"','"+g+"','"+e+"',
      '"+c+"','"+a+"');");
                   if(rs != 0)
                           {
                              %> <jsp:forward page="U_Login.jsp" /> <%
                           }

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        PreethiGowri,

        Thank you, I learned a trick. Much appreciated.

        Oralloy

        Comment

        Working...