List of usage examples for java.sql ResultSet getFloat
float getFloat(String columnLabel) throws SQLException;
ResultSet
object as a float
in the Java programming language. From source file:com.draagon.meta.manager.db.driver.GenericSQLDriver.java
protected void parseField(Object o, MetaField f, ResultSet rs, int j) throws SQLException { switch (f.getType()) { case MetaField.BOOLEAN: { boolean bv = rs.getBoolean(j); if (rs.wasNull()) { f.setBoolean(o, null);//from w ww .java2 s . c o m } else { f.setBoolean(o, new Boolean(bv)); } } break; case MetaField.BYTE: { byte bv = rs.getByte(j); if (rs.wasNull()) { f.setByte(o, null); } else { f.setByte(o, new Byte(bv)); } } break; case MetaField.SHORT: { short sv = rs.getShort(j); if (rs.wasNull()) { f.setShort(o, null); } else { f.setShort(o, new Short(sv)); } } break; case MetaField.INT: { int iv = rs.getInt(j); if (rs.wasNull()) { f.setInt(o, null); } else { f.setInt(o, new Integer(iv)); } } break; case MetaField.DATE: { Timestamp tv = rs.getTimestamp(j); if (rs.wasNull()) { f.setDate(o, null); } else { f.setDate(o, new java.util.Date(tv.getTime())); } } break; case MetaField.LONG: { long lv = rs.getLong(j); if (rs.wasNull()) { f.setLong(o, null); } else { f.setLong(o, new Long(lv)); } } break; case MetaField.FLOAT: { float fv = rs.getFloat(j); if (rs.wasNull()) { f.setFloat(o, null); } else { f.setFloat(o, new Float(fv)); } } break; case MetaField.DOUBLE: { double dv = rs.getDouble(j); if (rs.wasNull()) { f.setDouble(o, null); } else { f.setDouble(o, new Double(dv)); } } break; case MetaField.STRING: f.setString(o, rs.getString(j)); break; case MetaField.OBJECT: f.setObject(o, rs.getObject(j)); break; } }
From source file:oscar.oscarRx.data.RxPrescriptionData.java
private Prescription getPrescriptionFromRS(ResultSet rs, int demographicNo) throws SQLException { Prescription p = new Prescription(rs.getInt("drugid"), oscar.Misc.getString(rs, "provider_no"), demographicNo);// w w w . j a va 2 s .com p.setRxCreatedDate(rs.getDate("create_date")); p.setRxDate(rs.getDate("rx_date")); p.setEndDate(rs.getDate("end_date")); p.setWrittenDate(rs.getDate("written_date")); p.setBrandName(oscar.Misc.getString(rs, "BN")); p.setGCN_SEQNO(rs.getInt("GCN_SEQNO")); p.setCustomName(oscar.Misc.getString(rs, "customName")); p.setTakeMin(rs.getFloat("takemin")); p.setTakeMax(rs.getFloat("takemax")); p.setFrequencyCode(oscar.Misc.getString(rs, "freqcode")); p.setDuration(oscar.Misc.getString(rs, "duration")); p.setDurationUnit(oscar.Misc.getString(rs, "durunit")); p.setQuantity(oscar.Misc.getString(rs, "quantity")); p.setRepeat(rs.getInt("repeat")); p.setLastRefillDate(rs.getDate("last_refill_date")); p.setNosubs(rs.getInt("nosubs")); p.setPrn(rs.getInt("prn")); p.setSpecial(oscar.Misc.getString(rs, "special")); p.setArchived(oscar.Misc.getString(rs, "archived")); p.setGenericName(oscar.Misc.getString(rs, "GN")); p.setAtcCode(oscar.Misc.getString(rs, "ATC")); p.setScript_no(oscar.Misc.getString(rs, "script_no")); p.setRegionalIdentifier(oscar.Misc.getString(rs, "regional_identifier")); p.setUnit(oscar.Misc.getString(rs, "unit")); p.setUnitName(oscar.Misc.getString(rs, "unitName")); p.setMethod(oscar.Misc.getString(rs, "method")); p.setRoute(oscar.Misc.getString(rs, "route")); p.setDrugForm(oscar.Misc.getString(rs, "drug_form")); p.setCustomInstr(rs.getBoolean("custom_instructions")); p.setDosage(oscar.Misc.getString(rs, "dosage")); p.setLongTerm(rs.getBoolean("long_term")); p.setCustomNote(rs.getBoolean("custom_note")); p.setPastMed(rs.getBoolean("past_med")); p.setStartDateUnknown(rs.getBoolean("start_date_unknown")); p.setComment(rs.getString("comment")); if (rs.getObject("patient_compliance") == null) p.setPatientCompliance(null); else p.setPatientCompliance(rs.getBoolean("patient_compliance")); p.setOutsideProviderName(oscar.Misc.getString(rs, "outside_provider_name")); p.setOutsideProviderOhip(oscar.Misc.getString(rs, "outside_provider_ohip")); p.setPickupDate(rs.getDate("pickup_datetime")); p.setPickupTime(rs.getDate("pickup_datetime")); p.setETreatmentType(rs.getString("eTreatmentType")); p.setRxStatus(rs.getString("rxStatus")); if (rs.getObject("dispense_interval") != null) p.setDispenseInterval(rs.getInt("dispense_interval")); if (rs.getObject("refill_duration") != null) p.setRefillDuration(rs.getInt("refill_duration")); if (rs.getObject("refill_quantity") != null) p.setRefillQuantity(rs.getInt("refill_quantity")); // String datesRePrinted = oscar.Misc.getString(rs,"dates_reprinted"); // if( datesRePrinted != null && datesRePrinted.length() > 0 ) { // p.setNumPrints(datesRePrinted.split(",").length + 1); // } // else { // p.setNumPrints(1); // } return p; }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.ExtendedRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }//w w w . j ava 2 s. c o m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); buildFormatterAndNamesArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); boolean isKeyCol = false; boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, Element> keyCols = new TreeMap<String, Element>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElementNS(doc, AbstractDBO.ROW_NAME, NS); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; String colName = colNames[j]; isKeyCol = (!noKey && keyField.contains(new Integer(j))); isNull = false; col = parser.createElementNS(doc, colName, NS); if (isKeyCol) { parser.setAttribute(col, AbstractDBO.ID_NAME, String.valueOf(j)); } switch (metadata.getColumnType(j)) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); isNull = dateVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getDateFormat()); textVal = fF.formatDate(dateVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, AbstractDBO.DEFAULT_DATE_FORMAT); textVal = dateFormatter.format(dateVal); } } } break; case Types.DOUBLE: case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); if (fF != null) { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(numVal); } else { parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(numVal); } } break; case Types.BIGINT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: { BigDecimal bigdecimal = rs.getBigDecimal(j); isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); isNull = clob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (isKeyCol) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyCols.put(String.valueOf(j), col); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElementNS(doc, AbstractDBO.DATA_NAME, NS); parser.setAttribute(data, AbstractDBO.ID_NAME, id); Element key = parser.createElementNS(doc, AbstractDBO.KEY_NAME, NS); data.appendChild(key); for (Entry<String, Element> keyColsEntry : keyCols.entrySet()) { key.appendChild(keyColsEntry.getValue()); } keyCols.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:oscar.oscarRx.data.RxPrescriptionData.java
public Prescription[] getPrescriptionsByPatientHideDeleted(int demographicNo) { Prescription[] arr = {};//from w w w . j a v a2s . co m ArrayList lst = new ArrayList(); String sql = "SELECT * FROM drugs WHERE archived = 0 AND " + "demographic_no = " + demographicNo + " " + "ORDER BY position, rx_date DESC, drugId DESC"; try { // Get Prescription from database ResultSet rs; Prescription p; rs = DBHandler.GetSQL(sql); while (rs.next()) { p = new Prescription(rs.getInt("drugid"), oscar.Misc.getString(rs, "provider_no"), demographicNo); p.setRxCreatedDate(rs.getDate("create_date")); p.setRxDate(rs.getDate("rx_date")); p.setEndDate(rs.getDate("end_date")); p.setWrittenDate(rs.getDate("written_date")); p.setBrandName(oscar.Misc.getString(rs, "BN")); p.setGCN_SEQNO(rs.getInt("GCN_SEQNO")); p.setCustomName(oscar.Misc.getString(rs, "customName")); p.setTakeMin(rs.getFloat("takemin")); p.setTakeMax(rs.getFloat("takemax")); p.setFrequencyCode(oscar.Misc.getString(rs, "freqcode")); p.setDuration(oscar.Misc.getString(rs, "duration")); p.setDurationUnit(oscar.Misc.getString(rs, "durunit")); p.setQuantity(oscar.Misc.getString(rs, "quantity")); p.setRepeat(rs.getInt("repeat")); p.setLastRefillDate(rs.getDate("last_refill_date")); p.setNosubs(rs.getInt("nosubs")); p.setPrn(rs.getInt("prn")); p.setSpecial(oscar.Misc.getString(rs, "special")); p.setGenericName(oscar.Misc.getString(rs, "GN")); p.setAtcCode(oscar.Misc.getString(rs, "ATC")); p.setScript_no(oscar.Misc.getString(rs, "script_no")); p.setRegionalIdentifier(oscar.Misc.getString(rs, "regional_identifier")); p.setUnit(oscar.Misc.getString(rs, "unit")); p.setUnitName(oscar.Misc.getString(rs, "unitName")); p.setMethod(oscar.Misc.getString(rs, "method")); p.setRoute(oscar.Misc.getString(rs, "route")); p.setDrugForm(oscar.Misc.getString(rs, "drug_form")); p.setCustomInstr(rs.getBoolean("custom_instructions")); p.setDosage(oscar.Misc.getString(rs, "dosage")); p.setLongTerm(rs.getBoolean("long_term")); p.setCustomNote(rs.getBoolean("custom_note")); p.setPastMed(rs.getBoolean("past_med")); p.setStartDateUnknown(rs.getBoolean("start_date_unknown")); p.setComment(rs.getString("comment")); if (rs.getObject("patient_compliance") == null) p.setPatientCompliance(null); else p.setPatientCompliance(rs.getBoolean("patient_compliance")); p.setOutsideProviderName(oscar.Misc.getString(rs, "outside_provider_name")); p.setOutsideProviderOhip(oscar.Misc.getString(rs, "outside_provider_ohip")); p.setPickupDate(rs.getDate("pickup_datetime")); p.setPickupTime(rs.getDate("pickup_datetime")); p.setETreatmentType(rs.getString("eTreatmentType")); p.setRxStatus(rs.getString("rxStatus")); if (rs.getObject("dispense_interval") != null) p.setDispenseInterval(rs.getInt("dispense_interval")); if (rs.getObject("refill_duration") != null) p.setRefillDuration(rs.getInt("refill_duration")); if (rs.getObject("refill_quantity") != null) p.setRefillQuantity(rs.getInt("refill_quantity")); lst.add(p); } rs.close(); arr = (Prescription[]) lst.toArray(arr); } catch (SQLException e) { logger.error(sql, e); } finally { DbConnectionFilter.releaseThreadLocalDbConnection(); } return arr; }
From source file:oscar.oscarRx.data.RxPrescriptionData.java
public Prescription[] getPrescriptionsByPatient(int demographicNo) { Prescription[] arr = {};/*from w w w.jav a 2 s. c om*/ ArrayList lst = new ArrayList(); String sql = "SELECT * FROM drugs WHERE " + "demographic_no = " + demographicNo + " " + "ORDER BY position, rx_date DESC, drugId DESC"; try { // Get Prescription from database ResultSet rs; Prescription p; rs = DBHandler.GetSQL(sql); while (rs.next()) { p = new Prescription(rs.getInt("drugid"), oscar.Misc.getString(rs, "provider_no"), demographicNo); p.setRxCreatedDate(rs.getDate("create_date")); p.setRxDate(rs.getDate("rx_date")); p.setEndDate(rs.getDate("end_date")); p.setWrittenDate(rs.getDate("written_date")); p.setBrandName(oscar.Misc.getString(rs, "BN")); p.setGCN_SEQNO(rs.getInt("GCN_SEQNO")); p.setCustomName(oscar.Misc.getString(rs, "customName")); p.setTakeMin(rs.getFloat("takemin")); p.setTakeMax(rs.getFloat("takemax")); p.setFrequencyCode(oscar.Misc.getString(rs, "freqcode")); p.setDuration(oscar.Misc.getString(rs, "duration")); p.setDurationUnit(oscar.Misc.getString(rs, "durunit")); p.setQuantity(oscar.Misc.getString(rs, "quantity")); p.setRepeat(rs.getInt("repeat")); p.setLastRefillDate(rs.getDate("last_refill_date")); p.setNosubs(rs.getInt("nosubs")); p.setPrn(rs.getInt("prn")); p.setSpecial(oscar.Misc.getString(rs, "special")); p.setSpecialInstruction(oscar.Misc.getString(rs, "special_instruction")); p.setArchived(oscar.Misc.getString(rs, "archived")); p.setGenericName(oscar.Misc.getString(rs, "GN")); p.setAtcCode(oscar.Misc.getString(rs, "ATC")); p.setScript_no(oscar.Misc.getString(rs, "script_no")); p.setRegionalIdentifier(oscar.Misc.getString(rs, "regional_identifier")); p.setUnit(oscar.Misc.getString(rs, "unit")); p.setUnitName(oscar.Misc.getString(rs, "unitName")); p.setMethod(oscar.Misc.getString(rs, "method")); p.setRoute(oscar.Misc.getString(rs, "route")); p.setDrugForm(oscar.Misc.getString(rs, "drug_form")); p.setCustomInstr(rs.getBoolean("custom_instructions")); p.setDosage(oscar.Misc.getString(rs, "dosage")); p.setLongTerm(rs.getBoolean("long_term")); p.setCustomNote(rs.getBoolean("custom_note")); p.setPastMed(rs.getBoolean("past_med")); p.setStartDateUnknown(rs.getBoolean("start_date_unknown")); p.setComment(rs.getString("comment")); if (rs.getObject("patient_compliance") == null) p.setPatientCompliance(null); else p.setPatientCompliance(rs.getBoolean("patient_compliance")); p.setOutsideProviderName(oscar.Misc.getString(rs, "outside_provider_name")); p.setOutsideProviderOhip(oscar.Misc.getString(rs, "outside_provider_ohip")); p.setPickupDate(rs.getDate("pickup_datetime")); p.setPickupTime(rs.getDate("pickup_datetime")); p.setETreatmentType(rs.getString("eTreatmentType")); p.setRxStatus(rs.getString("rxStatus")); if (rs.getObject("dispense_interval") != null) p.setDispenseInterval(rs.getInt("dispense_interval")); if (rs.getObject("refill_duration") != null) p.setRefillDuration(rs.getInt("refill_duration")); if (rs.getObject("refill_quantity") != null) p.setRefillQuantity(rs.getInt("refill_quantity")); lst.add(p); } rs.close(); arr = (Prescription[]) lst.toArray(arr); } catch (SQLException e) { logger.error(sql, e); } finally { DbConnectionFilter.releaseThreadLocalDbConnection(); } return arr; }
From source file:piramide.interaction.reasoner.db.deploy.DatabaseMigrator.java
/** * Given the Downloaded table, we populate the Devices and Trends tables. *///from ww w. java 2s.c o m public void populateTables() { int invalidData = 0; try { final Connection con = DriverManager.getConnection(CONNECTION_URL, USERNAME, PASSWORD); final Statement stmtClearTrends = con.createStatement(); stmtClearTrends.execute("DELETE FROM Trends"); stmtClearTrends.close(); final Statement stmtClearDevices = con.createStatement(); stmtClearDevices.execute("DELETE FROM Devices"); stmtClearDevices.close(); con.setAutoCommit(false); final Statement stmtDownloaded = con.createStatement(); final ResultSet rsDownloaded = stmtDownloaded .executeQuery("SELECT device_name, wurfl_id, marketing_name, brand_name, model_name, " + "real_height, real_width, reso_height, " + "reso_width, value, region FROM Downloaded"); final List<String> deviceNames = new Vector<String>(); final PreparedStatement stmtDevices = con.prepareStatement( "" + "INSERT INTO Devices(device_name, wurfl_id, marketing_name, brand_name, model_name, " + "real_height, real_width, real_size, reso_height, reso_width, reso_size) " + "Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"); final PreparedStatement stmtTrends = con.prepareStatement( "" + "INSERT INTO Trends( device_name, region, month, year, value, error_margin ) " + "Values(?, ?, ?, ?, ?, ? )"); final Map<String, Integer> month2month = new HashMap<String, Integer>(); month2month.put("Jan", Integer.valueOf(1)); month2month.put("Feb", Integer.valueOf(2)); month2month.put("Mar", Integer.valueOf(3)); month2month.put("Apr", Integer.valueOf(4)); month2month.put("May", Integer.valueOf(5)); month2month.put("Jun", Integer.valueOf(6)); month2month.put("Jul", Integer.valueOf(7)); month2month.put("Aug", Integer.valueOf(8)); month2month.put("Sep", Integer.valueOf(9)); month2month.put("Oct", Integer.valueOf(10)); month2month.put("Nov", Integer.valueOf(11)); month2month.put("Dec", Integer.valueOf(12)); int counter = 0; final Set<String> badOnes = new HashSet<String>(); while (rsDownloaded.next()) { ++counter; if (counter % 100 == 0) { System.out.println("committed... " + counter); con.commit(); } final String deviceName = rsDownloaded.getString("device_name"); if (deviceName.equals("htc x7500") || deviceName.equals("samsung sgh-m300") || deviceName.equals("nokia verizon") || deviceName.equals("kddi a1407pt") || deviceName.equals("nokia thr880i") || deviceName.equals("softbank softbank 910t") || deviceName.equals("nokia 8860") || deviceName.equals("sony ericsson w580i") || deviceName.equals("motorola c139") || deviceName.equals("samsung stripe") || deviceName.equals("samsung sgh-c414") || deviceName.equals("samsung gt-e2121l") || deviceName.equals("samsung sgh-z400") || deviceName.equals("i-mobile 606") || deviceName.equals("softbank v302sh") || deviceName.equals("motorola krzr k1c")) continue; if (!deviceNames.contains(deviceName)) { stmtDevices.setString(1, deviceName); stmtDevices.setString(2, rsDownloaded.getString("wurfl_id")); stmtDevices.setString(3, rsDownloaded.getString("marketing_name")); stmtDevices.setString(4, rsDownloaded.getString("brand_name")); stmtDevices.setString(5, rsDownloaded.getString("model_name")); stmtDevices.setFloat(6, rsDownloaded.getFloat("real_height")); stmtDevices.setFloat(7, rsDownloaded.getFloat("real_width")); stmtDevices.setFloat(8, rsDownloaded.getFloat("real_height") * rsDownloaded.getFloat("real_width")); stmtDevices.setInt(9, rsDownloaded.getInt("reso_height")); stmtDevices.setInt(10, rsDownloaded.getInt("reso_width")); stmtDevices.setInt(11, rsDownloaded.getInt("reso_height") * rsDownloaded.getInt("reso_width")); stmtDevices.execute(); deviceNames.add(deviceName); } final String base64csv = rsDownloaded.getString("value"); final CsvReader csvReader2 = buildCSVReader(base64csv); if (!csvReader2.readRecord() && base64csv.length() != 924) { final byte[] binaryCSV = new Base64().decode(base64csv); final String stringCSV = new String(binaryCSV, "utf-8"); if (stringCSV.contains("could not be interpreted")) { badOnes.add(rsDownloaded.getString("region") + "@" + deviceName); } } final CsvReader csvReader = buildCSVReader(base64csv); int previousMonth = 0; int previousYear = 0; float currentValue = 0.0f; String currentErrorMargin = ""; boolean executed = false; while (csvReader.readRecord()) { executed = true; final String week = csvReader.get(0); final float value = Float.parseFloat(csvReader.get(1)); final String errorMargin = csvReader.get(2); final String[] weekParts = week.split(" "); final Integer monthString = month2month.get(weekParts[0]); if (monthString == null) { System.err.println("Failed to load device: " + deviceName); continue; } final int month = monthString.intValue(); final int year = Integer.parseInt(weekParts[2]); if (month == previousMonth && year == previousYear) { currentValue += value; currentErrorMargin = currentErrorMargin + "; " + errorMargin; continue; } final String region = rsDownloaded.getString("region"); //System.out.println(deviceName + " " + region + " " + month + " " + year); stmtTrends.setString(1, deviceName); stmtTrends.setString(2, region); stmtTrends.setInt(3, previousMonth); stmtTrends.setInt(4, previousYear); stmtTrends.setFloat(5, currentValue); stmtTrends.setString(6, currentErrorMargin); stmtTrends.execute(); currentValue = value; currentErrorMargin = errorMargin; previousMonth = month; previousYear = year; } if (!executed) { invalidData++; badOnes.add(rsDownloaded.getString("region") + "@" + deviceName); } } con.commit(); stmtDevices.close(); stmtTrends.close(); stmtDownloaded.close(); System.out.println("Counter: " + counter); System.out.println("Invalid data: " + invalidData); if (invalidData > 0) { final StringBuilder builder = new StringBuilder(); for (String badOne : badOnes) { builder.append(badOne); builder.append("\n"); } FileUtils.writeStringToFile(new File(INVALID_FILE_PATH), builder.toString()); System.err.println("Warning: data of " + invalidData + " mobile devices is wrong. Check which devices at " + INVALID_FILE_PATH); } } catch (Exception e) { e.printStackTrace(); } }
From source file:oscar.oscarRx.data.RxPrescriptionData.java
public ArrayList<Prescription> getPrescriptionsByScriptNo(int script_no, int demographicNo) { ArrayList<Prescription> lst = new ArrayList<Prescription>(); String sql = "select drugs.*, p.date_printed, p.dates_reprinted from drugs, prescription p where p.script_no = drugs.script_no and " + "drugs.script_no = " + script_no; try {//from w ww. j a v a 2 s .co m // Get Prescription from database ResultSet rs; Prescription p; String datesRePrinted; rs = DBHandler.GetSQL(sql); while (rs.next()) { p = new Prescription(rs.getInt("drugid"), oscar.Misc.getString(rs, "provider_no"), demographicNo); p.setRxCreatedDate(rs.getDate("create_date")); p.setRxDate(rs.getDate("rx_date")); p.setEndDate(rs.getDate("end_date")); p.setWrittenDate(rs.getDate("written_date")); p.setBrandName(oscar.Misc.getString(rs, "BN")); p.setGCN_SEQNO(rs.getInt("GCN_SEQNO")); p.setCustomName(oscar.Misc.getString(rs, "customName")); p.setTakeMin(rs.getFloat("takemin")); p.setTakeMax(rs.getFloat("takemax")); p.setFrequencyCode(oscar.Misc.getString(rs, "freqcode")); p.setDuration(oscar.Misc.getString(rs, "duration")); p.setDurationUnit(oscar.Misc.getString(rs, "durunit")); p.setQuantity(oscar.Misc.getString(rs, "quantity")); p.setRepeat(rs.getInt("repeat")); p.setLastRefillDate(rs.getDate("last_refill_date")); p.setNosubs(rs.getInt("nosubs")); p.setPrn(rs.getInt("prn")); p.setSpecial(oscar.Misc.getString(rs, "special")); p.setGenericName(oscar.Misc.getString(rs, "GN")); p.setAtcCode(oscar.Misc.getString(rs, "ATC")); p.setScript_no(oscar.Misc.getString(rs, "script_no")); p.setRegionalIdentifier(oscar.Misc.getString(rs, "regional_identifier")); p.setUnit(oscar.Misc.getString(rs, "unit")); p.setUnitName(oscar.Misc.getString(rs, "unitName")); p.setMethod(oscar.Misc.getString(rs, "method")); p.setRoute(oscar.Misc.getString(rs, "route")); p.setDrugForm(oscar.Misc.getString(rs, "drug_form")); p.setCustomInstr(rs.getBoolean("custom_instructions")); p.setDosage(oscar.Misc.getString(rs, "dosage")); p.setLongTerm(rs.getBoolean("long_term")); p.setCustomNote(rs.getBoolean("custom_note")); p.setPastMed(rs.getBoolean("past_med")); p.setStartDateUnknown(rs.getBoolean("start_date_unknown")); p.setComment(rs.getString("comment")); if (rs.getObject("patient_compliance") == null) p.setPatientCompliance(null); else p.setPatientCompliance(rs.getBoolean("patient_compliance")); p.setOutsideProviderName(oscar.Misc.getString(rs, "outside_provider_name")); p.setOutsideProviderOhip(oscar.Misc.getString(rs, "outside_provider_ohip")); p.setPrintDate(rs.getDate("date_printed")); p.setPickupDate(rs.getDate("pickup_datetime")); p.setPickupTime(rs.getDate("pickup_datetime")); p.setETreatmentType(rs.getString("eTreatmentType")); p.setRxStatus(rs.getString("rxStatus")); if (rs.getObject("dispense_interval") != null) p.setDispenseInterval(rs.getInt("dispense_interval")); if (rs.getObject("refill_duration") != null) p.setRefillDuration(rs.getInt("refill_duration")); if (rs.getObject("refill_quantity") != null) p.setRefillQuantity(rs.getInt("refill_quantity")); datesRePrinted = oscar.Misc.getString(rs, "dates_reprinted"); if (datesRePrinted != null && datesRePrinted.length() > 0) p.setNumPrints(datesRePrinted.split(",").length + 1); else p.setNumPrints(1); lst.add(p); } rs.close(); DbConnectionFilter.getThreadLocalDbConnection().close(); } catch (SQLException e) { logger.error(sql, e); } return lst; }
From source file:oscar.oscarRx.data.RxPrescriptionData.java
public Prescription[] getPrescriptionScriptsByPatient(int demographicNo) { Prescription[] arr = {};//from w w w. j a v a2s . c om ArrayList lst = new ArrayList(); String sql = "SELECT d.*, p.date_printed, p.dates_reprinted FROM drugs d, prescription p WHERE " + "d.demographic_no = " + demographicNo + " and d.script_no = p.script_no " + "ORDER BY position DESC" + ", rx_date DESC, drugId ASC"; try { // Get Prescription from database ResultSet rs; Prescription p; String datesRePrinted; rs = DBHandler.GetSQL(sql); while (rs.next()) { p = new Prescription(rs.getInt("drugid"), oscar.Misc.getString(rs, "provider_no"), demographicNo); p.setRxCreatedDate(rs.getDate("create_date")); p.setRxDate(rs.getDate("rx_date")); p.setEndDate(rs.getDate("end_date")); p.setWrittenDate(rs.getDate("written_date")); p.setBrandName(oscar.Misc.getString(rs, "BN")); p.setGCN_SEQNO(rs.getInt("GCN_SEQNO")); p.setCustomName(oscar.Misc.getString(rs, "customName")); p.setTakeMin(rs.getFloat("takemin")); p.setTakeMax(rs.getFloat("takemax")); p.setFrequencyCode(oscar.Misc.getString(rs, "freqcode")); p.setDuration(oscar.Misc.getString(rs, "duration")); p.setDurationUnit(oscar.Misc.getString(rs, "durunit")); p.setQuantity(oscar.Misc.getString(rs, "quantity")); p.setRepeat(rs.getInt("repeat")); p.setLastRefillDate(rs.getDate("last_refill_date")); p.setNosubs(rs.getInt("nosubs")); p.setPrn(rs.getInt("prn")); p.setSpecial(oscar.Misc.getString(rs, "special")); p.setArchived(oscar.Misc.getString(rs, "archived")); p.setGenericName(oscar.Misc.getString(rs, "GN")); p.setAtcCode(oscar.Misc.getString(rs, "ATC")); p.setScript_no(oscar.Misc.getString(rs, "script_no")); p.setRegionalIdentifier(oscar.Misc.getString(rs, "regional_identifier")); p.setUnit(oscar.Misc.getString(rs, "unit")); p.setUnitName(oscar.Misc.getString(rs, "unitName")); p.setMethod(oscar.Misc.getString(rs, "method")); p.setRoute(oscar.Misc.getString(rs, "route")); p.setDrugForm(oscar.Misc.getString(rs, "drug_form")); p.setCustomInstr(rs.getBoolean("custom_instructions")); p.setDosage(oscar.Misc.getString(rs, "dosage")); p.setLongTerm(rs.getBoolean("long_term")); p.setCustomNote(rs.getBoolean("custom_note")); p.setPastMed(rs.getBoolean("past_med")); p.setStartDateUnknown(rs.getBoolean("start_date_unknown")); p.setComment(rs.getString("comment")); if (rs.getObject("patient_compliance") == null) p.setPatientCompliance(null); else p.setPatientCompliance(rs.getBoolean("patient_compliance")); p.setOutsideProviderName(oscar.Misc.getString(rs, "outside_provider_name")); p.setOutsideProviderOhip(oscar.Misc.getString(rs, "outside_provider_ohip")); p.setPickupDate(rs.getDate("pickup_datetime")); p.setPickupTime(rs.getDate("pickup_datetime")); p.setETreatmentType(rs.getString("eTreatmentType")); p.setRxStatus(rs.getString("rxStatus")); if (rs.getObject("dispense_interval") != null) p.setDispenseInterval(rs.getInt("dispense_interval")); if (rs.getObject("refill_duration") != null) p.setRefillDuration(rs.getInt("refill_duration")); if (rs.getObject("refill_quantity") != null) p.setRefillQuantity(rs.getInt("refill_quantity")); datesRePrinted = oscar.Misc.getString(rs, "dates_reprinted"); if (datesRePrinted != null && datesRePrinted.length() > 0) { p.setNumPrints(datesRePrinted.split(",").length + 1); } else { p.setNumPrints(1); } p.setPrintDate(rs.getDate("date_printed")); p.setDatesReprinted(datesRePrinted); lst.add(p); } rs.close(); DbConnectionFilter.getThreadLocalDbConnection().close(); arr = (Prescription[]) lst.toArray(arr); } catch (SQLException e) { logger.error(sql, e); } return arr; }
From source file:massbank.DatabaseManager.java
public Record getAccessionData(String accessionId, String contributor) { Record acc = new Record(contributor); try {// w w w .ja v a 2s. c o m this.statementRECORD.setString(1, accessionId); ResultSet set = this.statementRECORD.executeQuery(); int compoundID = -1; int sampleID = -1; int instrumentID = -1; if (set.next()) { acc.ACCESSION(set.getString("ACCESSION")); acc.RECORD_TITLE(set.getString("RECORD_TITLE")); acc.DATE(set.getDate("DATE").toLocalDate()); acc.AUTHORS(set.getString("AUTHORS")); acc.LICENSE(set.getString("LICENSE")); acc.COPYRIGHT(set.getString("COPYRIGHT")); acc.PUBLICATION(set.getString("PUBLICATION")); compoundID = set.getInt("CH"); sampleID = set.getInt("SP"); instrumentID = set.getInt("AC_INSTRUMENT"); acc.AC_MASS_SPECTROMETRY_MS_TYPE(set.getString("AC_MASS_SPECTROMETRY_MS_TYPE")); acc.AC_MASS_SPECTROMETRY_ION_MODE(set.getString("AC_MASS_SPECTROMETRY_ION_MODE")); acc.PK_SPLASH(set.getString("PK_SPLASH")); this.statementAC_CHROMATOGRAPHY.setString(1, set.getString("ACCESSION")); this.statementAC_MASS_SPECTROMETRY.setString(1, set.getString("ACCESSION")); this.statementMS_DATA_PROCESSING.setString(1, set.getString("ACCESSION")); this.statementMS_FOCUSED_ION.setString(1, set.getString("ACCESSION")); this.statementCOMMENT.setString(1, set.getString("ACCESSION")); this.statementPEAK.setString(1, set.getString("ACCESSION")); this.statementPK_NUM_PEAK.setString(1, set.getString("ACCESSION")); this.statementANNOTATION_HEADER.setString(1, accessionId); ResultSet tmp = this.statementAC_CHROMATOGRAPHY.executeQuery(); List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.AC_CHROMATOGRAPHY(tmpList); tmp = this.statementAC_MASS_SPECTROMETRY.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.AC_MASS_SPECTROMETRY(tmpList); tmp = this.statementMS_DATA_PROCESSING.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.MS_DATA_PROCESSING(tmpList); tmp = this.statementMS_FOCUSED_ION.executeQuery(); tmpList.clear(); while (tmp.next()) tmpList.add(Pair.of(tmp.getString("SUBTAG"), tmp.getString("VALUE"))); acc.MS_FOCUSED_ION(tmpList); tmp = this.statementCOMMENT.executeQuery(); List<String> tmpList2 = new ArrayList<String>(); while (tmp.next()) tmpList2.add(tmp.getString("COMMENT")); acc.COMMENT(tmpList2); tmp = this.statementANNOTATION_HEADER.executeQuery(); // int PK_ANNOTATION_HEADER_numberOfTokens = -1; if (tmp.next()) { String PK_ANNOTATION_HEADER = tmp.getString("HEADER"); String[] PK_ANNOTATION_HEADER_tokens = PK_ANNOTATION_HEADER.split(" "); acc.PK_ANNOTATION_HEADER(Arrays.asList(PK_ANNOTATION_HEADER_tokens)); // PK_ANNOTATION_HEADER_numberOfTokens = PK_ANNOTATION_HEADER_tokens.length; } tmp = this.statementPEAK.executeQuery(); // acc.add("PK$PEAK", null, "m/z int. rel.int."); while (tmp.next()) { acc.PK_PEAK_ADD_LINE(Arrays.asList((Double) tmp.getDouble("PK_PEAK_MZ"), (Double) (double) tmp.getFloat("PK_PEAK_INTENSITY"), (Double) (double) tmp.getShort("PK_PEAK_RELATIVE"))); String PK_ANNOTATION = tmp.getString("PK_ANNOTATION"); if (PK_ANNOTATION != null) acc.PK_ANNOTATION_ADD_LINE(Arrays.asList(PK_ANNOTATION.split(" "))); } tmp = this.statementPK_NUM_PEAK.executeQuery(); while (tmp.next()) { acc.PK_NUM_PEAK(Integer.valueOf(tmp.getInt("PK_NUM_PEAK"))); } } else throw new IllegalStateException("accessionId '" + accessionId + "' is not in database"); if (compoundID == -1) throw new IllegalStateException("compoundID is not set"); this.statementCOMPOUND.setInt(1, compoundID); set = this.statementCOMPOUND.executeQuery(); while (set.next()) { String formulaString = set.getString("CH_FORMULA"); IMolecularFormula m = MolecularFormulaManipulator.getMolecularFormula(formulaString, DefaultChemObjectBuilder.getInstance()); acc.CH_FORMULA(m); acc.CH_EXACT_MASS(set.getDouble("CH_EXACT_MASS")); String smilesString = set.getString("CH_SMILES"); if (smilesString.equals("N/A")) acc.CH_SMILES(new AtomContainer()); else { IAtomContainer c = new SmilesParser(DefaultChemObjectBuilder.getInstance()) .parseSmiles(smilesString); acc.CH_SMILES(c); } String iupacString = set.getString("CH_IUPAC"); if (iupacString.equals("N/A")) acc.CH_IUPAC(new AtomContainer()); else { // Get InChIToStructure InChIToStructure intostruct = InChIGeneratorFactory.getInstance() .getInChIToStructure(iupacString, DefaultChemObjectBuilder.getInstance()); INCHI_RET ret = intostruct.getReturnStatus(); if (ret == INCHI_RET.WARNING) { // Structure generated, but with warning message System.out.println(acc.ACCESSION() + ": InChI warning: " + intostruct.getMessage()); } else if (ret != INCHI_RET.OKAY) { // Structure generation failed throw new IllegalArgumentException( "Can not parse INCHI string in \"CH$IUPAC\" field. Structure generation failed: " + ret.toString() + " [" + intostruct.getMessage() + "] for " + iupacString); } IAtomContainer iupac = intostruct.getAtomContainer(); acc.CH_IUPAC(iupac); } // TODO CH$CDK_DEPICT_SMILES // TODO CH$CDK_DEPICT_GENERIC_SMILES // TODO CH$CDK_DEPICT_STRUCTURE_SMILES // acc.add("CH$CDK_DEPICT_SMILES", null, set.getString("CH_CDK_DEPICT_SMILES")); // acc.add("CH$CDK_DEPICT_GENERIC_SMILES", null, set.getString("CH_CDK_DEPICT_GENERIC_SMILES")); // acc.add("CH$CDK_DEPICT_STRUCTURE_SMILES", null, set.getString("CH_CDK_DEPICT_STRUCTURE_SMILES")); } this.statementCH_LINK.setInt(1, compoundID); set = this.statementCH_LINK.executeQuery(); List<Pair<String, String>> tmpList = new ArrayList<Pair<String, String>>(); while (set.next()) { tmpList.add(Pair.of(set.getString("DATABASE_NAME"), set.getString("DATABASE_ID"))); } acc.CH_LINK(tmpList); this.statementCOMPOUND_COMPOUND_CLASS.setInt(1, compoundID); set = this.statementCOMPOUND_COMPOUND_CLASS.executeQuery(); List<String> tmpList2 = new ArrayList<String>(); while (set.next()) { this.statementCOMPOUND_CLASS.setInt(1, set.getInt("CLASS")); ResultSet tmp = this.statementCOMPOUND_CLASS.executeQuery(); while (tmp.next()) { tmpList2.add(tmp.getString("CH_COMPOUND_CLASS")); } } acc.CH_COMPOUND_CLASS(tmpList2); this.statementCOMPOUND_NAME.setInt(1, compoundID); set = this.statementCOMPOUND_NAME.executeQuery(); tmpList2.clear(); while (set.next()) { this.statementNAME.setInt(1, set.getInt("NAME")); ResultSet tmp = this.statementNAME.executeQuery(); while (tmp.next()) { tmpList2.add(tmp.getString("CH_NAME")); } } acc.CH_NAME(tmpList2); this.statementSAMPLE.setInt(1, sampleID); set = this.statementSAMPLE.executeQuery(); if (set.next()) { acc.SP_SCIENTIFIC_NAME(set.getString("SP_SCIENTIFIC_NAME")); acc.SP_LINEAGE(set.getString("SP_LINEAGE")); this.statementSP_LINK.setInt(1, set.getInt("ID")); ResultSet tmp = this.statementSP_LINK.executeQuery(); tmpList.clear(); while (tmp.next()) { String spLink = tmp.getString("SP_LINK"); String[] tokens = spLink.split(" "); tmpList.add(Pair.of(tokens[0], tokens[1])); } acc.SP_LINK(tmpList); this.statementSP_SAMPLE.setInt(1, set.getInt("ID")); tmp = this.statementSP_SAMPLE.executeQuery(); tmpList2.clear(); while (tmp.next()) { tmpList2.add(tmp.getString("SP_SAMPLE")); } acc.SP_SAMPLE(tmpList2); } if (instrumentID == -1) throw new IllegalStateException("instrumentID is not set"); this.statementINSTRUMENT.setInt(1, instrumentID); set = this.statementINSTRUMENT.executeQuery(); if (set.next()) { acc.AC_INSTRUMENT(set.getString("AC_INSTRUMENT")); acc.AC_INSTRUMENT_TYPE(set.getString("AC_INSTRUMENT_TYPE")); } else throw new IllegalStateException("instrumentID is not in database"); } catch (Exception e) { System.out.println("error: " + accessionId); e.printStackTrace(); return null; } // this.openConnection(); return acc; }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * This is the core method to retrieve a value for a column from a result set. Its primary * purpose is to call the appropriate method on the result set, and to provide an extension * point where database-specific implementations can change this behavior. * /*w ww .j a v a2 s .c om*/ * @param resultSet The result set to extract the value from * @param columnName The name of the column; can be <code>null</code> in which case the * <code>columnIdx</code> will be used instead * @param columnIdx The index of the column's value in the result set; is only used if * <code>columnName</code> is <code>null</code> * @param jdbcType The jdbc type to extract * @return The value * @throws SQLException If an error occurred while accessing the result set */ protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx, int jdbcType) throws SQLException { boolean useIdx = (columnName == null); Object value; switch (jdbcType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: value = useIdx ? resultSet.getString(columnIdx) : resultSet.getString(columnName); break; case Types.NUMERIC: case Types.DECIMAL: value = useIdx ? resultSet.getBigDecimal(columnIdx) : resultSet.getBigDecimal(columnName); break; case Types.BIT: case Types.BOOLEAN: value = new Boolean(useIdx ? resultSet.getBoolean(columnIdx) : resultSet.getBoolean(columnName)); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value = new Integer(useIdx ? resultSet.getInt(columnIdx) : resultSet.getInt(columnName)); break; case Types.BIGINT: value = new Long(useIdx ? resultSet.getLong(columnIdx) : resultSet.getLong(columnName)); break; case Types.REAL: value = new Float(useIdx ? resultSet.getFloat(columnIdx) : resultSet.getFloat(columnName)); break; case Types.FLOAT: case Types.DOUBLE: value = new Double(useIdx ? resultSet.getDouble(columnIdx) : resultSet.getDouble(columnName)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: value = useIdx ? resultSet.getBytes(columnIdx) : resultSet.getBytes(columnName); break; case Types.DATE: value = useIdx ? resultSet.getDate(columnIdx) : resultSet.getDate(columnName); break; case Types.TIME: value = useIdx ? resultSet.getTime(columnIdx) : resultSet.getTime(columnName); break; case Types.TIMESTAMP: value = useIdx ? resultSet.getTimestamp(columnIdx) : resultSet.getTimestamp(columnName); break; case Types.CLOB: Clob clob = useIdx ? resultSet.getClob(columnIdx) : resultSet.getClob(columnName); if (clob == null) { value = null; } else { long length = clob.length(); if (length > Integer.MAX_VALUE) { value = clob; } else if (length == 0) { // the javadoc is not clear about whether Clob.getSubString // can be used with a substring length of 0 // thus we do the safe thing and handle it ourselves value = ""; } else { value = clob.getSubString(1l, (int) length); } } break; case Types.BLOB: Blob blob = useIdx ? resultSet.getBlob(columnIdx) : resultSet.getBlob(columnName); if (blob == null) { value = null; } else { long length = blob.length(); if (length > Integer.MAX_VALUE) { value = blob; } else if (length == 0) { // the javadoc is not clear about whether Blob.getBytes // can be used with for 0 bytes to be copied // thus we do the safe thing and handle it ourselves value = new byte[0]; } else { value = blob.getBytes(1l, (int) length); } } break; case Types.ARRAY: value = useIdx ? resultSet.getArray(columnIdx) : resultSet.getArray(columnName); break; case Types.REF: value = useIdx ? resultSet.getRef(columnIdx) : resultSet.getRef(columnName); break; default: value = useIdx ? resultSet.getObject(columnIdx) : resultSet.getObject(columnName); break; } return resultSet.wasNull() ? null : value; }