2012-05-02 62 views
1

我試着運行像下面JdbcTemplate的多發變量

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? 

謝謝 阿南德

回答

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. 
    } 
} 
+0

不,閱讀javadocs。請給我們一點點努力。 – duffymo