我正在改写我的问题,因为显然有些人无意中冒犯了(我是 Java 新手):(
我正在连接到一个 DB2 数据库——结果集包含表 V_LVCS 中的前 10 行。
我希望做到这一点!
while (rs.next())
{ keys[i] = new V_LVCS();
keys[i] = this_Row_Object;
}
我在一组 V_LVCS 对象之后。目前我正在将每个数据行转换为 V_LVCS 对象,如下所示,但我认为有更好更快的方法来执行此操作。
public class V_LVCS {
public String SERIAL;
public String TRANSFORMERID;
public String LVT;
public V_LVCS() {
}
public V_LVCS(String Serial, String Transformerid, String lvt) {
this.SERIAL = Serial;
this.TRANSFORMERID = Transformerid;
this.LVT = lvt;
}
public V_LVCS[] getAllV_LVC() {
try {
Connection conn = getAMMDBConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs;
rs = stmt.executeQuery("SELECT * FROM V_LVC FETCH FIRST 10 ROWS ONLY");
rs.last();
int numRows = rs.getRow();
V_LVCS[] keys = new V_LVCS[numRows];
rs.beforeFirst();
int i = 0;
while (rs.next()) {
keys[i] = new V_LVCS();
keys[i].SERIAL = (rs.getString("SERIAL") == null) ? "" : rs.getString("SERIAL");
keys[i].LVT = (rs.getString("LVT") == null) ? "" : rs.getString("LVT");
keys[i].TRANSFORMERID = (rs.getString("TRANSFORMERID") == null) ? "" : rs.getString("TRANSFORMERID");
++i;
}
conn.close();
System.out.println("stop!");
return keys;
} catch (Exception e) {
System.err.println("Got an exception! ");
// System.err.println(e.printStackTrace());
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return null;
}
}
}
我真的很感激你的想法!(并希望在受到 -ve 分数的惩罚之前能坚持几个小时!)