title: java.sql.SQLException: Can not issue data manipulation statements with executeQuery() in java servlet program
body: <pre><code>public class CreateAccount extends HttpServlet 
  {
  
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
          throws ServletException, IOException {
  
      Connection con=null;
      PreparedStatement pstm=null;
      PreparedStatement pstm1=null;
  
      PrintWriter pw=resp.getWriter();
      String name=req.getParameter("txt_name");
      String contact=req.getParameter("txt_contact");
      String email=req.getParameter("txt_email");
      String pin=req.getParameter("txt_pass");
      String address=req.getParameter("txt_address");
      String accType=req.getParameter("txt_accType");
      String gender=req.getParameter("radio_gender");
      String city=req.getParameter("txt_city");
      String state=req.getParameter("txt_state");
  
      String url="jdbc:mysql://localhost:3306/bankapp";
      String user="root";
      String dbpass="pass";
  
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
          con=DriverManager.getConnection(url, user, dbpass);
          String sql="INSERT INTO AccountDetails VALUES(?,?,?,?,?,?,?,?,?,?,?)";
          pstm=con.prepareStatement(sql);
          pstm.setString(1, name);
          pstm.setString(2, contact);
          pstm.setString(3, email);
          pstm.setString(4, pin);
          pstm.setString(5, address);
          pstm.setString(6, accType);
          pstm.setString(7, gender);
          pstm.setString(8, city);
          pstm.setString(9, state);
          pstm.setString(10, null);
          pstm.setString(11, null);
  
          pstm.executeUpdate();
  
          String sql1="SELECT accNumber FROM AccountDetails WHERE email=?";
          pstm1=con.prepareStatement(sql1);
          pstm.setString(1, email);
          ResultSet rs=pstm.executeQuery();
          int accnum=0;
          while(rs.next()){
              accnum=rs.getInt("accNumber");
          }
  
  
          pw.write("&lt;html&gt;&lt;head&gt;Dear "+name+" Thankyou For Registering With Us&lt;/br&gt;");
          pw.write("Your Account Number Is :"+accnum+"&lt;/head&gt;&lt;/html&gt;");
      } catch (ClassNotFoundException e) {
  
          e.printStackTrace();
      } catch (SQLException e) {
  
          e.printStackTrace();
          pw.write("&lt;html&gt;&lt;head&gt;Oops Something Wrong With Our Database"+e+"&lt;/head&gt;&lt;/html&gt;");
      }finally {
          try {
              pstm.close();
              //pstm1.close();
              con.close();
          } catch (SQLException e) {
  
              e.printStackTrace();
              pw.write("&lt;html&gt;&lt;head&gt;Something Wrong With Connection"+e+"&lt;/head&gt;&lt;/html&gt;");
          }
      }
  
  
  
  }
  
  
  }
  </code></pre>
  
  <p>I have Used The MySQL Database Where I've Taken The column "accNumber" as INT(10) and also as Primary Key. 
  I Used Everything that is possible to get the value from the result set, But I'm getting the same error again and again.
  Please Help Me Guy's.</p>