dbrowsequence.java

来自「java xml开发指南(初学者推荐)Java Xml 编程指南书籍源码」· Java 代码 · 共 72 行

JAVA
72
字号
package MyNa.xml;

import java.sql.*;
import java.util.Hashtable;
import java.util.Enumeration;
import MyNa.utils.*;


public class DBRowSequence extends RowSeq {
  ResultSet theResultSet; Logger lg;

public DBRowSequence(ResultSet R,Env queryInfo)
    throws SQLException,Exception{
  super(); lg=new Logger();
  theResultSet=R; theEnv=queryInfo;
  if(R==null){
    theColumnLabels=null;
    theColumnTypes=null;
    theColumnValues=null;
    theNumberOfColumns=0;
   }else{
  theColumnLabels=MiscDB.resultSetLabels(R);
  theColumnTypes=MiscDB.resultSetTypes(R);
  theEnv.put("theColumnLabels",theColumnLabels);
  theEnv.put("theColumnTypes",theColumnTypes);
  setInitEnv();
  }
}
public DBRowSequence(ResultSet R)
    throws SQLException,Exception{
  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=0;i<theNumberOfColumns;i++){
      String S=theResultSet.getString(i+1);
      if(S==null)S="";
      theColumnValues[i]=S;
      theEnv.put(theColumnLabels[i],S);
      theEnv.put(theFieldValueNum[i],S);
      }
    return true;
}catch(Exception E){lg.logIt("DBSequence.next ERROR:",E);}
  return false;
}
public Env getRow(){
  return theEnv;
}

public void close(){
 try{theResultSet.close(); theResultSet=null;}
 catch(Exception ex){lg.logIt("DBRowSequence.close",ex);}
}
// tools for inheritance, e.g. pruning a rowsequence.


public void shallowClone(RowSeq re){ // a shallow copy
  super.shallowClone(re);
  if(re instanceof DBRowSequence)
    this.theResultSet=((DBRowSequence)re).theResultSet;
}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?