Q:

How to fix ''Incorrect result size: expected 1, actual 0' thouhj I'm querying for a single object?

I want to open a new JSP page where there is only one row of a table. But when I run this it shows me this error with wrong size. I'm querying for one object only... (I'm choosing tables dynamically)
private final String SQL_RPL_TABLE_NAME = "?tableName?";
private final String SQL_SELECT_NAME_SPRAV = "SELECT sprav_name FROM sprav_of_spravs WHERE id = ?";
private final String SQL_SELECT_ROW = "select * from " + SQL_RPL_TABLE_NAME + " where id = ?";

@Override
    public Spravochnik selectOne(int spravochnikId, int rowId) {
        return jdbctemplate.queryForObject(getQueryDinamicTable(SQL_SELECT_ROW, getSpravNameAtId(spravochnikId)),
                new Object[] { spravochnikId }, Spravochnik.class);
    }

    protected String getSpravNameAtId(int spravochnikId) {
        return jdbctemplate.queryForObject(SQL_SELECT_NAME_SPRAV, new Object[] { spravochnikId }, String.class);
    }

    protected String getQueryDinamicTable(String query, String tableName) {
        return query.replace(SQL_RPL_TABLE_NAME, tableName).intern();
    }

Service
    @Override
    public Spravochnik selectOne(String id) {
        return spravochnikDao.selectOne(getSpravId(id), getRowId(id) );
    }

    protected int getSpravId(String id) {
        return Integer.valueOf(id.substring(0, 3));
    }

    protected int getRowId(String id) {
        return Integer.valueOf(id);
    }

and Controller
    @RequestMapping(value = "/edit", method = { RequestMethod.POST, RequestMethod.GET })
    public ModelAndView edit(@RequestParam("id") String id, @RequestParam("tableName") String tableName,
            ModelMap model) {
        Spravochnik sprav = spravochnikService.selectOne(id);

        model.addAttribute("tableName", tableName);
        model.addAttribute("sprav", sprav);

        return new ModelAndView("edit", model);
    }

(tableName I get from the previous jsp where I list the whole table so it's fine)
Plese, could you tell where is my mistake? Thanks in advance!

A:

In case it might help anyone change the method of selectOne to use your RowMapper:  @Override
    public Spravochnik selectOne(int spravochnikId, int rowId) {
        return jdbctemplate.queryForObject(getQueryDinamicTable(SQL_SELECT_ROW, getSpravNameAtId(spravochnikId)),
                new SpravochnikRowMapper(), rowId);
    }

