关于object []的使用
我有个函数如下,它接收一个object[]参数,我就是不知道怎么用?
public ResultSet executeQuery(String sql,Object[] params)
throws SQLException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement(sql);
//设置参数
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (params[i] != null) {
stmt.setObject(i + 1, params[i]);
} else {
stmt.setNull(i + 1, Types.OTHER);
}
}
}
//得到结果
rs = stmt.executeQuery();
} catch (SQLException e) {
// this.rethrow(e, sql, params);
}
return rs;//esult;
}
比如我想executeQuery("select a from tab where id=?",..)这最后一个参数怎么传?