- // Create a ResultSetHandler implementation to convert the
- // first row into an Object[].
- ResultSetHandler<Object[]> h = new ResultSetHandler<Object[]>() {
- public Object[] handle(ResultSet rs) throws SQLException {
- if (!rs.next()) {
- return null;
- }
- ResultSetMetaData meta = rs.getMetaData();
- int cols = meta.getColumnCount();
- Object[] result = new Object[cols];
- for (int i = 0; i < cols; i++) {
- result[i] = rs.getObject(i + 1);
- }
- return result;
- }
- };
- // Create a QueryRunner that will use connections from
- // the given DataSource
- QueryRunner run = new QueryRunner(dataSource);
- // Execute the query and get the results back from the handler
- Object[] result = run.query(
- "SELECT * FROM Person WHERE name=?", h, "John Doe");
- //该片段来自于http://www.codesnippet.cn/detail/191220121072.html
来源: http://www.codesnippet.cn/detail/191220121072.html