1

我正在尝试运行如下查询

select col1 from table1 where col2 = ? and col3 = ?

我想使用 JdbcTemplate

我可以这样写吗?

String query = new String("select col1 from table1 where col2 = ? and col3 = ?");
Object[] parameters = new Object[] {new String(col2), new String(col3)};

Object module = jdbcTemplate.queryForObject(query, parameters,"");


**Object module = jdbcTemplate.queryForObject(query, parameters,String.class);** is this right?
4

1 回答 1

1

JdbcTemplate有该方法的几个重载版本。你打算打电话给哪一个?

您可以RowMapper为您感兴趣的对象类型添加一个实现。这就是我的建议。

public class YourRowMapper implements RowMapper<YourClass> {
    YourClass mapRow(ResultSet rs, int rowNum) throws SQLException {
        return new YourClass();  // map the ResultSet row here.
    }
}
于 2012-05-02T11:43:29.660 回答