本文整理汇总了Java中org.apache.commons.dbutils.handlers.ArrayHandler类的典型用法代码示例。如果您正苦于以下问题:Java ArrayHandler类的具体用法?Java ArrayHandler怎么用?Java ArrayHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayHandler类属于org.apache.commons.dbutils.handlers包,在下文中一共展示了ArrayHandler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadFromMetaData
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
/**
* @see #loadFromMetaData(RecordMetaData)
*/
@Override
public List<Record> loadFromMetaData(List<RecordMetaData> recordMetaDatas) throws IOException {
List<Record> ret = new ArrayList<>();
for (RecordMetaData rmd : recordMetaDatas) {
if (!(rmd instanceof RecordMetaDataJdbc)) {
throw new IllegalArgumentException(
"Invalid metadata; expected RecordMetaDataJdbc instance; got: " + rmd);
}
QueryRunner runner = new QueryRunner();
String request = ((RecordMetaDataJdbc) rmd).getRequest();
try {
Object[] item = runner
.query(this.conn, request, new ArrayHandler(), ((RecordMetaDataJdbc) rmd).getParams().toArray());
ret.add(new org.datavec.api.records.impl.Record(toWritable(item), rmd));
} catch (SQLException e) {
throw new IllegalArgumentException("Could not execute statement \"" + request + "\"", e);
}
}
return ret;
}
示例2: setUp
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this); // init the mocks
when(dataSource.getConnection()).thenReturn(conn);
when(conn.prepareStatement(any(String.class))).thenReturn(stmt);
when(stmt.getParameterMetaData()).thenReturn(meta);
when(stmt.getResultSet()).thenReturn(results);
when(stmt.executeQuery()).thenReturn(results);
when(conn.prepareCall(any(String.class))).thenReturn(call);
when(call.getParameterMetaData()).thenReturn(meta);
when(call.getResultSet()).thenReturn(results);
when(call.getMoreResults()).thenReturn(false);
when(results.next()).thenReturn(false);
handler = new ArrayHandler();
runner = new QueryRunner(dataSource);
}
示例3: queryArray
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
public Object[] queryArray(String sql, Object... params) {
Object[] array;
try {
array = queryRunner.query(sql, new ArrayHandler(), params);
} catch (SQLException e) {
logger.error("查询出错!");
throw new RuntimeException(e);
}
printSQL(sql);
return array;
}
示例4: queryArray
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
public static Object[] queryArray(QueryRunner runner, String sql, Object... params) {
Object[] result;
try {
result = runner.query(sql, new ArrayHandler(), params);
} catch (SQLException e) {
logger.error("查询出错!", e);
throw new RuntimeException(e);
}
printSQL(sql);
return result;
}
示例5: test1
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
@Test
public void test1() throws SQLException{//���Խ������ÿһ�м�¼����һ�������У�ע���������Ƕ��У�ֻ���ص�һ�м�¼
QueryRunner runner=new QueryRunner(JdbcUtils.getDataSource());//ͨ������һ�����ݿ����ӳأ�����һ��dbutils�������Ӳ��������ֶ��ͷţ�dbutils��ܻ�������ͷ�
String sql="select * from users where id=?";
Object res[]=(Object[]) runner.query(sql, 1, new ArrayHandler());
for(int i=0;i<res.length;i++){
System.out.println(res[i]);
}
}
示例6: findArray
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
/**
* //TODO 查询数组
*
* @param sql
* @param params
* @return
*/
public static Object[] findArray(String sql, Object... params) {
Object[] array;
try {
array = getQueryRunner().query(sql, new ArrayHandler(), params);
} catch (SQLException e) {
logger.error("queryArray.查询数组出错:" + sql, e);
throw new QueryException(e);
}
logger.debug("sql:" + sql + "\n params:" + Arrays.toString(params));
return array;
}
示例7: setUp
import org.apache.commons.dbutils.handlers.ArrayHandler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(dataSource.getConnection()).thenReturn(conn);
when(conn.prepareStatement(any(String.class))).thenReturn(stmt);
when(stmt.getParameterMetaData()).thenReturn(meta);
when(stmt.getResultSet()).thenReturn(results);
when(stmt.executeQuery()).thenReturn(results);
when(results.next()).thenReturn(false);
handler = new ArrayHandler();
runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1), new QueryRunner(dataSource));
}