📄 dbset.java
字号:
package org.digitstore.util;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 数据结果集类
* <P>
*
* @author zhengyan
*/
public class DBSet extends Vector {
private Hashtable htColumn = new Hashtable();
private Hashtable info = new Hashtable();
Log logger = LogFactory.getLog(this.getClass());
/**
* Constructor
*/
public DBSet() {
}
/**
*
*/
public void put(String key, String value) {
htColumn.put(key, value);
}
public void printColumnInfo() {
logger.debug("Column Info:" + htColumn);
}
/**
* 设置信息
*/
public void setInfo(String Key, Object info) {
this.info.put(Key, info);
}
/**
* 取信息
*/
public Object getInfo(String Key) {
return info.get(Key);
}
public int getColumnIndex(String column_name) {
if (this.size() == 0) {
return -1;
}
String ind = (String) htColumn.get(column_name.toUpperCase());
if (ind == null) {
logger.debug("列名" + column_name
+ "错误导致getColumnIndex(String column_name)方法出错");
return -1;
} else {
return Integer.parseInt(ind);
}
}
/**
* 得到row行, col列的值,row,col均从0开始
*/
public String get(int row, int col) {
return (String) ((Vector) elementAt(row)).elementAt(col);
}
/**
* 得到row行, col字段的值。 row从0开始
*/
public String get(int row, String column_name) {
return get(row, getColumnIndex(column_name));
}
/**
* 得到一行的值。 row从0开始
*
* @return 一维向量
*/
public Vector getRow(int row) {
if (getRowCount() < row) {
return null;
}
return (Vector) elementAt(row);
}
/**
* 得到一列的值
*
* @param col
* 列的序号
*/
public Vector getColumn(int col) {
Vector ret = new Vector();
for (int i = 0; i < getRowCount(); i++) {
ret.add(((Vector) elementAt(i)).elementAt(col));
}
return ret;
}
/**
* 得到一列的值
*
* @param colName
* 列名
*/
public Vector getColumn(String colName) {
return getColumn(getColumnIndex(colName));
}
/**
* 得到行数
*/
public int getRowCount() {
return size();
}
/**
* 得到列数,如果没有得到纪录返回0
*/
public int getColCount() {
if (getRowCount() == 0) {
return 0; //如果没有得到纪录返回0
}
return ((Vector) elementAt(0)).size();
}
public int getColumnCount() {
return getColCount();
}
public void set(int row, int column, Object value) {
((Vector) this.get(row)).set(column, value);
}
/**
* 替换某一列的值(规则替换编码)
*
* @param ht
* 比如{{key=1,value='已审核'}}
* @param columnName
*/
public void replace(Hashtable ht, String columnName) {
int ind = getColumnIndex(columnName);
for (int i = 0; i < size(); i++) {
set(i, ind, ht.get(get(i, ind)));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -