0
@Override
public int getData(String username, String password) {
    // TODO Auto-generated method stub
    int Status = 1;
    String sql = "select UserId from UserRegister where UserName=? and Password=? and Status=?;";
    int userid = jdbcTemplate.queryForObject(sql, new Object[] { username,
            password, Status }, Integer.class);
    if (userid != 0) {
        return userid;
    } else {
        userid = 0;
        return userid;
    }

}

Exception:

org.springframework.web.util.NestedServletException: Request
processing failed; nested exception is
org.springframework.dao.EmptyResultDataAccessException: Incorrect
result size: expected 1, actual 0
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
Joz
  • 11
  • 3
  • Take a look at http://stackoverflow.com/questions/10606229/jdbctemplate-query-for-string-emptyresultdataaccessexception-incorrect-result – Balwinder Singh Aug 10 '16 at 06:43
  • here the parameters along with the query is integer values. if we need to pass the parameters along with the query what we will do? – Joz Aug 10 '16 at 09:23

1 Answers1

0

try it once it may helps you.

String sql = "select UserId from UserRegister where UserName=? and Password=?  and Status=?";
int userid = (Integer)jdbcTemplate.queryForInt(sql, new Object[] { username,
        password, Status }, Integer.class);
Suman Behara
  • 150
  • 9
  • thanku for your answer ,but i not works for me..here some problem with the queryforobject returns should be atleast one . thatsy exception is coming. could u say about that? – Joz Aug 10 '16 at 09:22