数据库查询的片断如下:
public Collection getFaultwithtype(String argType)
throws Exception {
PreparedStatement prepStmt = null;
ResultSet rs = null;
ArrayList <FaultBean> list = new ArrayList <FaultBean> ();
String sql = "select fnum, fdate, fweek, substring(starttime,1,2)+ ': '+substring(starttime,3,2) as starttime, substring(endtime,1,2)+ ': '+substring(endtime,3,2) as endtime, ftype, fplace, ffinish, fperson, flinkman, fphone, funit, fbehave, fcause, fnote from kpfault where ftype = ? ";
Connection con = null;
try {
con = getConnection();
if (con.isClosed()) {
throw new IllegalStateException( "ERROR.THE CONNECTION ISCLOSED ");
}
prepStmt = con.prepareStatement(sql);
prepStmt.setString(1, argType);
rs = prepStmt.executeQuery();
while (rs.next()) {
FaultBean fB = new FaultBean();
int fnum = rs.getInt( "fnum ");
String fnum1 = Integer.toString(fnum);
fB.setFnum(fnum1);
fB.setFdate(rs.getString( "fdate "));
String fweek = rs.getString( "fweek ");
if (fweek != null || fweek.equals( " ")) {
fweek = new String(fweek.getBytes( "ISO-8859-1 "), "GB2312 ");
}
fB.setFweek(fweek);
fB.setStarttime(rs.getString( "starttime "));
fB.setEndtime(rs.getString( "endtime "));
String ftype = rs.getString( "ftype ");
if (ftype != null || ftype.equals( " ")) {
ftype = new String(ftype.getBytes( "ISO-8859-1 "), "GB2312 ");
}
fB.setFtype(ftype);
String fplace = rs.getString( "fplace ");
if (fplace != null || fplace.equals( " ")) {
fplace = new String(fplace.getBytes( "ISO-8859-1 "), "GB2312 ");
}
fB.setFplace(fplace);
String ffinish = rs.getString( "ffinish ");
if (ffinish != null || ffinish.equals( " ")) {
ffinish = new String(ffinish.getBytes( "ISO-8859-1 "),
"GB2312 ");
}
fB.setFfinish(ffinish);
String fperson = rs.getString( "fperson ");
if (fperson != null || fperson.equals( " ")) {
fperson = new String(fperson.getBytes( "ISO-8859-1 "),
"GB2312 ");
}
fB.setFperson(fperson);
String flinkman = rs.getString( "flinkman ");
if (flinkman != null || flinkman.equals( " ")) {
flinkman = new String(flinkman.getBytes( "ISO-8859-1 "),
"GB2312 ");
}
fB.setFlinkman(flinkman);
fB.setFphone(rs.getString( "fphone "));