数据库中的数据表有两部分组成,表头和数据记录。可以使用以下数据结构
import java.io.Serializable;
import java.util.List;
import java.util.Map;
public final class DBRecords implements Serializable {
private final Map<String, Integer> catalog;
private final List<String[]> records;
public DBRecords(final Map<String, Integer> catalog, final List<String[]> records) {
this.catalog = catalog;
this.records = records;
}
public final int getColumnIndex(final String name) {
if (catalog.containsKey(name))
return catalog.get(name);
return -1;
}
public final List<String[]> getRecords() {
return records;
}
public final Map<String, Integer> getCatalog() {
return catalog;
}
public int size() {
if (records != null)
return records.size();
return 0;
}
public boolean isEmpty() {
if (records == null || records.isEmpty())
return true;
return false;
}
public String[] get(int id) {
if (records.size() <= id || id < 0)
return null;
return records.get(id);
}
}