title: My Select query is not working in Spring MVC 3 using MySql Database
body: <p>My DAO Class:</p>
  
  <pre><code>public boolean RetreiveId(UserBean userBean){
      boolean userExists = false;
  
      /* Provide table name and column name carefully in the sql query below.
       * here i have a table "userbean" with two column's
       * "userId" and "password" both of varchar2 type.
       */
               String sql1 = "select userId from userbean "+"where userId = ?";
   jdbcTemplate.update(sql1, new Object[] { userBean.getUserId()});
                              System.out.println("^^^^^^^^^^sql1"+sql1);
              int rowcount=1;
            if(rowcount==1){
          userExists = true;
      }
      return userExists;
  }
  }
  </code></pre>
  
  <p>MyController Class</p>
  
  <pre><code>@RequestMapping("/RetreiveId")
  public ModelAndView RetreiveId(@ModelAttribute @Valid UserBean      userBean,BindingResult result,HttpSession session){
      ModelAndView view = new ModelAndView("loginLatest");
  
      //if input bean does not have validation error then proceed
      if(!result.hasFieldErrors()){
          //if not a valid user then add error
          //else proceed to user welcome page
  
  
                         if(!combatService.RetreiveId(userBean)){
              result.addError(new ObjectError("err", "Invalid Credentials"));
          }
  //          if(!combatService.RegisterUser(userBean)){
  //              result.addError(new ObjectError("err", "Invalid Credentials"));
  //          }
  //          else{
  //                            session.setAttribute("Sess_Var", userBean.getUserId());
  ////                             view.addObject("Sess_Var", userBean.getUserId());
  //              view.setViewName("welcome");
  //          }
  
                         else{
  //                            session.setAttribute("Sess_Var", userBean.getUserId());
  //                             view.addObject("Sess_Var", userBean.getUserId());
              view.setViewName("loginLatest");
                         }
      }
  </code></pre>
  
  <p>It is not working, it is giving error, Insert Query is working well but I want to retrieve the password of a particular username </p>
  
  <pre><code>Request processing failed; nested exception is     
  org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL      
  [select userId from userbean where userId = ?]; Can not issue executeUpdate() for   
  SELECTs; nested exception is java.sql.SQLException: Can not issue executeUpdate() for     
  SELECTs
  </code></pre>