By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,805 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,805 IT Pros & Developers. It's quick & easy.

Error: ResultSet was not produced

P: 1
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.
Expand|Select|Wrap|Line Numbers
  1. <%    
  2.         try
  3.     {
  4.             String n=request.getParameter("name");
  5.             String u=request.getParameter("uname");
  6.             String p=request.getParameter("pwd");
  7.             String y=request.getParameter("Year");
  8.             String g=request.getParameter("Gender");
  9.             String e=request.getParameter("EmailID");
  10.             String c=request.getParameter("Moblie");
  11.             String a=request.getParameter("Address");
  12.     Connection con=DriverManager.getConnection("jdbc:odbc:uinfo; uid=System; pwd=tandon");
  13.             Statement st=con.createStatement();
  14.             ResultSet rs=st.executeQuery("insert into uinfo values('"+n+"','"+u+"','"+p+"','"+y+"','"+g+"','"+e+"','"+c+"','"+a+"');");
  15.              if(rs.next())
  16.                      {
  17.                         %> <jsp:forward page="U_Login.jsp" /> <%
  18.                      }
  19.             else
  20.                 {
  21.                 out.println("please retry");
  22.           %><br><br> <a href="http://bytes.com/SignUp.jsp">Back to Home</a> <%
  23.                    }         
  24.   con.close();
  25.  
  26.          }               
  27.         catch(Exception e)
  28.          {
  29.          out.println(e);
  30.          }
  31.         %>
May 24 '13 #1
Share this Question
Share on Google+
3 Replies


Oralloy
Expert 100+
P: 983
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
May 26 '13 #2

100+
P: 126
ExecuteUpdate has to be used instead of ExecuteQuery for insert, update and delete queries. Write something like,

Expand|Select|Wrap|Line Numbers
  1.  Statement st=con.createStatement();
  2.             int rs=st.executeUpdate("insert into uinfo values('"+n+"',
  3. '"+u+"','"+p+"','"+y+"','"+g+"','"+e+"',
  4. '"+c+"','"+a+"');");
  5.              if(rs != 0)
  6.                      {
  7.                         %> <jsp:forward page="U_Login.jsp" /> <%
  8.                      }
May 27 '13 #3

Oralloy
Expert 100+
P: 983
PreethiGowri,

Thank you, I learned a trick. Much appreciated.

Oralloy
May 28 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.