怎样将返回list型,改为返回数组型,附具体函数
或者改写这个方法也可 这个思路比较清晰
public List quyListBySql(String querystr,int dno) throws
SQLException {
Connection conn=null;
Statement stmt = null;
ResultSet rst=null;
ResultSetMetaData rsmd = null;
List tmplist=new ArrayList();
//查询异常标志,为false时为正常情况,为true时为异常情况
String quyErrorFlag = "false";
Map tmpmap = null;
try {
//获取链接
conn = myDataUtil.getConnection(dno);
//ResultSet中数据可以双向滚动;指定可以更新 ResultSet
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
rst = stmt.executeQuery(querystr);
rsmd = rst.getMetaData();
while(rst.next()){
tmpmap = new HashMap();
for ( int j = 1; j <= rsmd.getColumnCount(); j++ ){
tmpmap.put(rsmd.getColumnName(j), rst.getObject(j));
}
tmplist.add(tmpmap);
}
tmpmap = new HashMap();
tmpmap.put("quyErrorFlag",quyErrorFlag);
tmplist.add(0,tmpmap);
}catch(Exception e){
tmpmap = new HashMap();
quyErrorFlag = "true";
tmpmap.put("quyErrorFlag",quyErrorFlag);
tmplist.add(0,tmpmap);
System.out.println("pubgetstr"+e.toString()+querystr);
}finally{
//释放资源
myDataUtil.free(rst,stmt,conn);
return tmplist;
}
}
------解决方案--------------------
Java code
public Object[] quyArraysBySql(String querystr,int dno) throws SQLException {
List list = quyListBySql(querystr, dno);
int size = list.size();
Object[] arrays = new Object[size];
for(int i = 0; i < size; i++){
arrays[i] = list.get(i);
}
return arrays;
}
------解决方案--------------------