这儿碰到了一个比较好的方法(与数据库的操作),返回一个ArrayList。方法如下:
public ArrayList sqlExecute(String sql) throws SQLException {
ArrayList alResult = new ArrayList();
try {
connection = getConnection();
cstmt = connection.createStatement();
rstRet = (ResultSet) cstmt.executeQuery(sql);
ResultSetMetaData rsmd = rstRet.getMetaData();
int numCols = rsmd.getColumnCount();
while (rstRet.next()) {
String strTempArray[] = new String[numCols];
for (int i = 1; i <= numCols; i++) {
strTempArray[i - 1] = rstRet.getString(i) == null ? "":rstRet.getString(i);
}
alResult.add(strTempArray);
}
dbclose();
} catch (DAOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return alResult;
}
感觉很好,以后一定会用得到。