/** * @param columnIdx * @param obj * @roseuid 3E5D8981013E */ public void setObject(int columnIdx, Object obj) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); record.set(columnIdx, obj); }
/** * @param columnIdx * @return Object * @roseuid 3E5D894200B1 */ public Object getObject(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return null; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); Object value = record.get(columnIdx); return value; }
public String getTimeString(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return null; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); Object value = record.get(columnIdx); if (value == null) return null; return value.toString().trim().split("\\.")[0]; }
/** * @param columnIdx * @return String * @roseuid 3E5D88F000F9 */ public String getString(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return null; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); Object value = record.get(columnIdx); if (value == null) return ""; if ((rmd.getType() == MetaDataTypes.CALENDAR_TP) || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) { String[] DateStr = value.toString().trim().split("\\."); return DateStr[0]; } return value.toString().trim(); }
/** * 只有String和Boolean类型进行转换,其他类型均返回false * * @param columnIdx * @return boolean * @roseuid 3E5D883200BA */ public boolean getBoolean(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return false; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); if (rmd.getType() == MetaDataTypes.STRING_TP) { Record record = (Record) records.get(currentNo); String value = (String) record.get(columnIdx); if (value == null || value.equals("0")) return false; return true; } if (rmd.getType() == MetaDataTypes.BOOLEAN_TP) { Record record = (Record) records.get(currentNo); Boolean value = (Boolean) record.get(columnIdx); return value.booleanValue(); } else { return false; } }
/** * @param columnIdx * @return double * @roseuid 3E5D88C701AE */ public double getDouble(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return 0; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); Object value = record.get(columnIdx); if (value == null) return 0; switch (rmd.getType()) { case MetaDataTypes.BIGDECIMAL_TP: return ((BigDecimal) value).doubleValue(); case MetaDataTypes.BIGINTEGER_TP: return ((BigInteger) value).doubleValue(); case MetaDataTypes.BOOLEAN_TP: Boolean b = (Boolean) value; if (b.booleanValue()) return 1; else return 0; case MetaDataTypes.DOUBLE_TP: return ((Double) value).doubleValue(); case MetaDataTypes.FLOAT_TP: return ((Float) value).doubleValue(); case MetaDataTypes.INTEGER_TP: return ((Integer) value).doubleValue(); case MetaDataTypes.LONG_TP: return ((Long) value).doubleValue(); case MetaDataTypes.SHORT_TP: return ((Short) value).doubleValue(); case MetaDataTypes.STRING_TP: try { return Double.parseDouble((String) value); } catch (Exception e) { return 0; } default: return 0; } // switch }
/** * @param columnIdx * @return java.util.Calendar * @roseuid 3E5D8903036D */ public java.util.Date getCalendar(int columnIdx) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return null; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); Object value = record.get(columnIdx); if (value == null) { return null; } else { } if ((rmd.getType() == MetaDataTypes.CALENDAR_TP) || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) { java.util.Date d = (java.util.Date) value; // Calendar c=Calendar.getInstance(); // c.set(1900+d.getYear(),d.getMonth(),d.getDate()); return d; } else { return null; } }
private void init(ResultSet rs, int resultNo) { if (rs == null) return; try { ResultSetMetaData rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); for (int i = 1; i <= count; i++) { String name = rsmd.getColumnName(i); if (name != null) name = name.toLowerCase(); String typeName = rsmd.getColumnClassName(i); String caption = rsmd.getColumnLabel(i); RecordMetaData rmd = new RecordMetaData(name, typeName, caption, i); metadata.put(name, rmd); fieldNames.add(name); } fieldCount = count; while (rs.next()) { ArrayList record = new ArrayList(); for (int i = 1; i <= count; i++) { String name = (String) fieldNames.get(i - 1); RecordMetaData rmd = (RecordMetaData) metadata.get(name); // System.out.println(rmd.getType()); switch (rmd.getType()) { case MetaDataTypes.BIGDECIMAL_TP: case MetaDataTypes.BIGINTEGER_TP: record.add(rs.getBigDecimal(i)); break; case MetaDataTypes.BOOLEAN_TP: record.add(new Boolean(rs.getBoolean(i))); break; case MetaDataTypes.BYTE_TP: record.add(new Byte(rs.getByte(i))); break; case MetaDataTypes.CALENDAR_TP: java.sql.Date d = rs.getDate(i); // Calendar calendar = GregorianCalendar.getInstance(); // System.out.println("aaaaaaaa"+d); // calendar.set(d.getYear()+1900,d.getMonth(),d.getDay()); record.add(d); break; case MetaDataTypes.CHARACTER_TP: break; case MetaDataTypes.DOUBLE_TP: record.add(new Double(rs.getDouble(i))); break; case MetaDataTypes.FLOAT_TP: record.add(new Float(rs.getFloat(i))); break; case MetaDataTypes.INTEGER_TP: record.add(new Integer(rs.getInt(i))); break; case MetaDataTypes.LONG_TP: record.add(new Long(rs.getLong(i))); break; case MetaDataTypes.SHORT_TP: record.add(new Short(rs.getShort(i))); break; case MetaDataTypes.STRING_TP: record.add(DBUtil.fromDB(rs.getString(i))); break; default: InputStream is = rs.getBinaryStream(i); record.add(is); } // switch } // for records.add(new Record(record)); recordCount++; if (recordCount == resultNo) { break; } } // while } catch (SQLException sqle) { sqle.printStackTrace(); } }
public String getFieldName(int columnIdx) { String name = (String) fieldNames.get(columnIdx); return name; }