欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

DBUtils 的基本使用示例,DBUtils使用示例,java代码// Cre

来源: javaer 分享于  点击 29406 次 点评:243

DBUtils 的基本使用示例,DBUtils使用示例,java代码// Cre


java代码

// 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 DataSourceQueryRunner run = new QueryRunner(dataSource);// Execute the query and get the results back from the handlerObject[] result = run.query(    "SELECT * FROM Person WHERE name=?", h, "John Doe");
相关栏目:

用户点评