📄 rowsequence.java
字号:
package MyNa.utils;
import java.sql.*;
import java.util.Hashtable;
/* the RowSequence provides access to a ResultSet as
an sequence of Env (extended Hashtable) structures:
with RowSequence rS,
rS.next() will shift to the next Env and return true,
reading and processing a row -- or fail.
and rS.getRow() will return the current Env.
*/
public class RowSequence {
ResultSet theResultSet; Env theEnv;
String [] theColumnLabels; String [] theColumnTypes;
String [] theColumnValues;
int theNumberOfColumns;
public RowSequence(ResultSet R,Env queryInfo)
throws SQLException{
theResultSet=R; theEnv=queryInfo;
if(R==null){
theColumnLabels=null;
theColumnTypes=null;
theColumnValues=null;
theNumberOfColumns=0;
}else{
theColumnLabels=MiscDB.resultSetLabels(R);
theColumnTypes=MiscDB.resultSetTypes(R);
theNumberOfColumns=theColumnLabels.length;
theColumnValues=new String[theNumberOfColumns];
theEnv.put("NumberOfColumns",""+theNumberOfColumns);
theEnv.put("FieldName",theColumnLabels);
theEnv.put("FieldType",theColumnTypes);
theEnv.put("FieldValue",theColumnValues);
for(int i=1;i<=theNumberOfColumns;i++)
theEnv.put("FieldName"+i,theColumnLabels[i-1]);
}
}
public RowSequence(ResultSet R)
throws SQLException{
this(R,new Env());
}
public boolean next(){
if(theResultSet==null)return false;
try{
if(!theResultSet.next()){
theResultSet.close();
theResultSet=null;
return false;
}
for(int i=1;i<=theNumberOfColumns;i++){
String S=theResultSet.getString(i);
theColumnValues[i-1]=S;
theEnv.put(theColumnLabels[i-1],S);
theEnv.put("FieldValue"+i,S);
}
return true;
}catch(Exception E){}
return false;
}
public Env getRow(){
return theEnv;
}
// tools for inheritance, e.g. pruning a RowSequence.
public void initFromRowSequence(RowSequence re){ // a shallow copy
this.theResultSet=re.theResultSet;
this.theEnv=re.theEnv;
this.theColumnLabels=re.theColumnLabels;
this.theColumnTypes=re.theColumnTypes;
this.theColumnValues=re.theColumnValues;
this.theNumberOfColumns=re.theNumberOfColumns;
}
public RowSequence(){} // a do-nothing empty constructor
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -