List of usage examples for java.sql ResultSet getDouble
double getDouble(String columnLabel) throws SQLException;
ResultSet
object as a double
in the Java programming language. From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8SchemaDoubleTable.java
protected MSSBamSchemaDoubleBuff unpackSchemaDoubleResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackSchemaDoubleResultSetToBuff"; int idxcol = 1; String classCode = resultSet.getString(idxcol); idxcol++;//from www . j av a 2 s . co m MSSBamSchemaDoubleBuff buff; if (classCode.equals("SDBL")) { buff = schema.getFactorySchemaDouble().newBuff(); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Unrecognized class code \"" + classCode + "\""); } buff.setRequiredId(resultSet.getLong(idxcol)); idxcol++; buff.setRequiredTenantId(resultSet.getLong(idxcol)); idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalScopeId(null); } else { buff.setOptionalScopeId(colVal); } } idxcol++; buff.setRequiredName(resultSet.getString(idxcol)); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalShortName(null); } else { buff.setOptionalShortName(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalLabel(null); } else { buff.setOptionalLabel(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalShortDescription(null); } else { buff.setOptionalShortDescription(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalDescription(null); } else { buff.setOptionalDescription(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalAuthorId(null); } else { buff.setOptionalAuthorId(colVal); } } idxcol++; buff.setRequiredValueContainerId(resultSet.getLong(idxcol)); idxcol++; buff.setRequiredIsNullable(resultSet.getBoolean(idxcol)); idxcol++; { boolean colVal = resultSet.getBoolean(idxcol); if (resultSet.wasNull()) { buff.setOptionalGenerateId(null); } else { buff.setOptionalGenerateId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalDataScopeId(null); } else { buff.setOptionalDataScopeId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalViewAccessSecurityId(null); } else { buff.setOptionalViewAccessSecurityId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalEditAccessSecurityId(null); } else { buff.setOptionalEditAccessSecurityId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalViewAccessFrequencyId(null); } else { buff.setOptionalViewAccessFrequencyId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalEditAccessFrequencyId(null); } else { buff.setOptionalEditAccessFrequencyId(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalPrevId(null); } else { buff.setOptionalPrevId(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalNextId(null); } else { buff.setOptionalNextId(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalDbName(null); } else { buff.setOptionalDbName(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalInitValue(null); } else { buff.setOptionalInitValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalDefaultValue(null); } else { buff.setOptionalDefaultValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalMinValue(null); } else { buff.setOptionalMinValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalMaxValue(null); } else { buff.setOptionalMaxValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalNullValue(null); } else { buff.setOptionalNullValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalUnknownValue(null); } else { buff.setOptionalUnknownValue(colVal); } } idxcol++; buff.setRequiredContainerId(resultSet.getLong(idxcol)); idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); }
From source file:com.cmart.DB.CassandraDBQuery.java
private HashMap<Long, Item> getItemsByID(ArrayList<Long> ids, String column) { HashMap<Long, Item> items = new HashMap<Long, Item>(); if (ids == null || ids.size() == 0) return items; int attemptsRemaining = SQL_RETRIES; do {//from w w w . j av a 2 s . c o m Connection conn = this.getConnection(); if (conn != null) { PreparedStatement statement = null; try { StringBuffer keys = new StringBuffer(); boolean start = true; for (long l : ids) { if (!start) keys.append(","); keys.append("'"); keys.append(l); keys.append("'"); start = false; } statement = conn.prepareStatement( "SELECT * FROM " + column + " WHERE KEY IN (" + keys.toString() + ")"); ResultSet rs = statement.executeQuery(); while (rs.next()) { Item currentItem; // Check the results are real long tempid = 0; try { tempid = rs.getLong("sellerid"); } catch (Exception e) { tempid = 0; } if (tempid == 0) { currentItem = null; } else { ArrayList<Image> images = this.getItemImages(rs.getLong("KEY")); currentItem = new Item(rs.getLong("KEY"), new String(rs.getString("name")), new String(rs.getString("description")), new Integer((int) rs.getLong("quantity")), rs.getDouble("startprice"), rs.getDouble("reserveprice"), rs.getDouble("buynowprice"), rs.getDouble("curbid"), rs.getDouble("maxbid"), new Integer((int) rs.getLong("noofbids")), new Date(rs.getLong("startdate")), new Date(rs.getLong("enddate")), rs.getLong("sellerid"), rs.getLong("categoryid"), new String(rs.getString("thumbnail")), images); items.put(rs.getLong("KEY"), currentItem); } } rs.close(); attemptsRemaining = 0; } catch (CommunicationsException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (MySQLNonTransientConnectionException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (Exception e) { System.out.println("CassandraQuery (getitemsbyid): Could not get the items"); e.printStackTrace(); } finally { this.closeSmt(statement); this.closeConnection(conn); } } attemptsRemaining--; } while (attemptsRemaining >= 0); return items; }
From source file:com.cmart.DB.CassandraDBQuery.java
public Item getOldItem(long itemID, Boolean getImages) { if (itemID < 1) return null; Item result = null;/* w w w.ja v a2 s . c om*/ int attemptsRemaining = SQL_RETRIES; do { Connection conn = this.getConnection(); if (conn != null) { PreparedStatement statement = null; try { // Create the SQL statement to see get the item's details statement = conn.prepareStatement("SELECT * FROM olditems WHERE KEY=" + itemID); ResultSet rs = statement.executeQuery(); // If an item is returned then get the details if (rs.next()) { long seller = 0; try { Long temp = rs.getLong("sellerid"); if (temp != null) seller = temp; } catch (Exception e) { } if (seller != 0) { // If we need to get the images, do that now ArrayList<Image> images = new ArrayList<Image>(); if (getImages == true) images = this.getItemImages(rs.getLong("KEY")); result = new Item(rs.getLong("KEY"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"), rs.getDouble("startprice"), rs.getDouble("reserveprice"), rs.getDouble("buynowprice"), rs.getDouble("curbid"), rs.getDouble("maxbid"), rs.getInt("noofbids"), new Date(rs.getLong("startdate")), new Date(rs.getLong("enddate")), rs.getLong("sellerid"), rs.getLong("categoryid"), rs.getString("thumbnail"), images); } } rs.close(); attemptsRemaining = 0; } catch (CommunicationsException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (MySQLNonTransientConnectionException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (Exception e) { System.err.println("CassandraQuery (getItem): Could not get the item"); e.printStackTrace(); } finally { this.closeSmt(statement); this.closeConnection(conn); } } attemptsRemaining--; } while (attemptsRemaining >= 0); return result; }
From source file:com.cmart.DB.CassandraDBQuery.java
public Item getItem(long itemID, Boolean getImages) { if (itemID < 1) return null; Item result = null;/* w w w .j a v a2 s .c om*/ int attemptsRemaining = SQL_RETRIES; do { Connection conn = this.getConnection(); if (conn != null) { PreparedStatement statement = null; try { // Create the SQL statement to see get the item's details statement = conn.prepareStatement("SELECT * FROM items WHERE KEY=" + itemID); ResultSet rs = statement.executeQuery(); // If an item is returned then get the details if (rs.next()) { // Make sure the value is real. The problem here is that Cassandra will return the // key if it ever existed long seller = 0; try { Long temp = rs.getLong("sellerid"); if (temp != null) seller = temp; } catch (Exception e) { } if (seller != 0) { // If we need to get the images, do that now ArrayList<Image> images = new ArrayList<Image>(); if (getImages == true) images = this.getItemImages(rs.getLong("KEY")); result = new Item(rs.getLong("KEY"), rs.getString("name"), rs.getString("description"), rs.getInt("quantity"), rs.getDouble("startprice"), rs.getDouble("reserveprice"), rs.getDouble("buynowprice"), rs.getDouble("curbid"), rs.getDouble("maxbid"), rs.getInt("noofbids"), new Date(rs.getLong("startdate")), new Date(rs.getLong("enddate")), rs.getLong("sellerid"), rs.getLong("categoryid"), rs.getString("thumbnail"), images); } } rs.close(); attemptsRemaining = 0; } catch (CommunicationsException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (MySQLNonTransientConnectionException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (Exception e) { System.err.println("CassandraQuery (getItem): Could not get the item " + itemID); e.printStackTrace(); } finally { this.closeSmt(statement); this.closeConnection(conn); } } attemptsRemaining--; } while (attemptsRemaining >= 0); return result; }
From source file:com.glaf.dts.transform.MxTransformThread.java
@SuppressWarnings("unchecked") public void run() { logger.debug(taskId + "----------------execution-----------------"); TransformTask task = transformTaskService.getTransformTask(taskId); if (task != null) { if (task.getStatus() == 9 || task.getRetryTimes() > 3) { return; }// www . j a v a2s . com task.setStartTime(new java.util.Date()); task.setRetryTimes(task.getRetryTimes() + 1); task.setStatus(1); transformTaskService.save(task); } List<TableModel> resultList = new java.util.ArrayList<TableModel>(); Map<String, Object> singleDataMap = new HashMap<String, Object>(); Connection conn = null; PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; boolean success = true; long start = System.currentTimeMillis(); logger.debug("start:" + DateUtils.getDateTime(new java.util.Date())); try { Database database = getDatabaseService().getDatabaseById(queryDefinition.getDatabaseId()); if (database != null) { conn = DBConnectionFactory.getConnection(database.getName()); } else { conn = DBConnectionFactory.getConnection(); } logger.debug("conn:" + conn.toString()); String sql = queryDefinition.getSql(); sql = QueryUtils.replaceSQLVars(sql); List<Object> values = null; if (paramMap != null) { SqlExecutor sqlExecutor = JdbcUtils.rebuildSQL(sql, paramMap); sql = sqlExecutor.getSql(); values = (List<Object>) sqlExecutor.getParameter(); } logger.debug("--------------execute query----------------------"); logger.debug(queryDefinition.getTitle()); logger.debug("::sql::" + sql); psmt = conn.prepareStatement(sql); if (values != null && !values.isEmpty()) { JdbcUtils.fillStatement(psmt, values); logger.debug("::values::" + values); } List<ColumnDefinition> columns = new java.util.ArrayList<ColumnDefinition>(); rs = psmt.executeQuery(); rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); for (int i = 1; i <= count; i++) { int sqlType = rsmd.getColumnType(i); ColumnDefinition column = new ColumnDefinition(); column.setColumnName(rsmd.getColumnName(i)); column.setColumnLabel(rsmd.getColumnLabel(i)); column.setJavaType(FieldType.getJavaType(sqlType)); column.setPrecision(rsmd.getPrecision(i)); column.setScale(rsmd.getScale(i)); columns.add(column); } Set<String> cols = new HashSet<String>(); while (rs.next()) { int index = 0; TableModel rowModel = new TableModel(); ColumnModel cell01 = new ColumnModel(); cell01.setColumnName("ID"); cell01.setType("String"); rowModel.addColumn(cell01); rowModel.setIdColumn(cell01); cols.add(cell01.getColumnName()); ColumnModel cell04 = new ColumnModel(); cell04.setColumnName("AGGREGATIONKEY"); cell04.setType("String"); rowModel.addColumn(cell04); cols.add(cell04.getColumnName()); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); /** * ???? */ if (cols.contains(column.getColumnName())) { continue; } ColumnModel cell = new ColumnModel(); String columnName = column.getColumnName(); String javaType = column.getJavaType(); cell.setColumnName(columnName); cell.setType(javaType); index = index + 1; if ("String".equals(javaType)) { String value = rs.getString(columnName); cell.setStringValue(value); cell.setValue(value); } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(columnName); cell.setIntValue(value); cell.setValue(value); } catch (Exception e) { String str = rs.getString(columnName); logger.error("integer:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setIntValue(num.intValue()); cell.setValue(cell.getIntValue()); logger.debug("?:" + num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(columnName); cell.setLongValue(value); cell.setValue(value); } catch (Exception e) { String str = rs.getString(columnName); logger.error("long:" + str); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setLongValue(num.longValue()); cell.setValue(cell.getLongValue()); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(columnName); cell.setDoubleValue(d); cell.setValue(d); } catch (Exception e) { String str = rs.getString(columnName); logger.error("double:" + str); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); cell.setDoubleValue(num.doubleValue()); cell.setValue(cell.getDoubleValue()); logger.debug("?:" + num.doubleValue()); } } else if ("Boolean".equals(javaType)) { Boolean value = rs.getBoolean(columnName); cell.setBooleanValue(value); cell.setValue(value); } else if ("Date".equals(javaType)) { Date value = rs.getTimestamp(columnName); cell.setDateValue(value); cell.setValue(value); } else { String value = rs.getString(columnName); cell.setStringValue(value); cell.setValue(value); } rowModel.addColumn(cell); if (resultList.isEmpty()) { singleDataMap.put(column.getColumnLabel(), cell.getValue()); } } resultList.add(rowModel); } logger.debug("--------------------resultList size:" + resultList.size()); } catch (Exception ex) { success = false; ex.printStackTrace(); logger.error(ex); throw new RuntimeException(ex); } finally { JdbcUtils.close(rs); JdbcUtils.close(psmt); JdbcUtils.close(conn); if (!success) { if (task != null) { task.setStatus(2); transformTaskService.save(task); } } } logger.debug("--------------execute mybatis save----------------------"); try { if (!StringUtils.equalsIgnoreCase(queryDefinition.getRotatingFlag(), "R2C")) { TransformTable tbl = new TransformTable(); tbl.createOrAlterTable(tableDefinition); } List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tableDefinition.getTableName()); if (columns != null && !columns.isEmpty()) { tableDefinition.setColumns(columns); } if (resultList != null && !resultList.isEmpty() && tableDefinition.getTableName() != null && tableDefinition.getAggregationKeys() != null) { logger.debug("RotatingFlag:" + queryDefinition.getRotatingFlag()); logger.debug("RotatingColumn:" + queryDefinition.getRotatingColumn()); /** * ???? */ if (StringUtils.equalsIgnoreCase(queryDefinition.getRotatingFlag(), "R2C") && StringUtils.isNotEmpty(queryDefinition.getRotatingColumn()) && resultList.size() == 1) { logger.debug("?dataMap?:" + singleDataMap); logger.debug("AggregationKeys:" + tableDefinition.getAggregationKeys()); ColumnDefinition idField = columnMap.get(tableDefinition.getAggregationKeys().toLowerCase()); ColumnDefinition field = columnMap.get(queryDefinition.getRotatingColumn().toLowerCase()); logger.debug("idField:" + idField); logger.debug("field:" + field); if (idField != null && field != null) { String javaType = field.getJavaType(); List<TableModel> list = new ArrayList<TableModel>(); Set<Entry<String, Object>> entrySet = singleDataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (key == null || value == null) { continue; } TableModel tableModel = new TableModel(); tableModel.setTableName(queryDefinition.getTargetTableName()); ColumnModel cell = new ColumnModel(); cell.setColumnName(queryDefinition.getRotatingColumn()); cell.setType(javaType); // logger.debug(cell.getColumnName()+"->"+javaType); if ("String".equals(javaType)) { cell.setStringValue(ParamUtils.getString(singleDataMap, key)); cell.setValue(cell.getStringValue()); } else if ("Integer".equals(javaType)) { cell.setIntValue(ParamUtils.getInt(singleDataMap, key)); cell.setValue(cell.getIntValue()); } else if ("Long".equals(javaType)) { cell.setLongValue(ParamUtils.getLong(singleDataMap, key)); cell.setValue(cell.getLongValue()); } else if ("Double".equals(javaType)) { cell.setDoubleValue(ParamUtils.getDouble(singleDataMap, key)); cell.setValue(cell.getDoubleValue()); } else if ("Date".equals(javaType)) { cell.setDateValue(ParamUtils.getDate(singleDataMap, key)); cell.setValue(cell.getDateValue()); } else { cell.setValue(value); } tableModel.addColumn(cell); ColumnModel idColumn = new ColumnModel(); idColumn.setColumnName(tableDefinition.getAggregationKeys()); idColumn.setJavaType(idField.getJavaType()); idColumn.setValue(key); tableModel.setIdColumn(idColumn); list.add(tableModel); } logger.debug("update datalist:" + list); tableDataService.updateTableData(list); } } else { tableDataService.saveAll(tableDefinition, null, resultList); } } resultList.clear(); resultList = null; long time = System.currentTimeMillis() - start; if (task != null) { task.setEndTime(new java.util.Date()); task.setStatus(9); task.setDuration(time); } logger.debug("execute time(ms)--------------------------" + time); } catch (Exception ex) { if (task != null) { task.setStatus(2); } ex.printStackTrace(); logger.error(ex); throw new RuntimeException(ex); } finally { if (task != null) { transformTaskService.save(task); if (task.getStatus() != 9) { this.run(); } } } }
From source file:com.glaf.core.jdbc.QueryHelper.java
/** * @param conn// www . java 2 s . c o m * ? * @param sqlExecutor * * @return */ @SuppressWarnings("unchecked") public List<Map<String, Object>> getResultList(Connection conn, SqlExecutor sqlExecutor) { if (!DBUtils.isLegalQuerySql(sqlExecutor.getSql())) { throw new RuntimeException(" SQL statement illegal "); } List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; try { psmt = conn.prepareStatement(sqlExecutor.getSql()); if (sqlExecutor.getParameter() != null) { List<Object> values = (List<Object>) sqlExecutor.getParameter(); JdbcUtils.fillStatement(psmt, values); } rs = psmt.executeQuery(); if (conf.getBoolean("useMyBatisResultHandler", false)) { resultList = this.getResults(rs); } else { rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); List<ColumnDefinition> columns = new ArrayList<ColumnDefinition>(); for (int index = 1; index <= count; index++) { int sqlType = rsmd.getColumnType(index); ColumnDefinition column = new ColumnDefinition(); column.setIndex(index); column.setColumnName(rsmd.getColumnName(index)); column.setColumnLabel(rsmd.getColumnLabel(index)); column.setJavaType(FieldType.getJavaType(sqlType)); column.setPrecision(rsmd.getPrecision(index)); column.setScale(rsmd.getScale(index)); if (column.getScale() == 0 && sqlType == Types.NUMERIC) { column.setJavaType("Long"); } column.setName(StringTools.camelStyle(column.getColumnLabel().toLowerCase())); columns.add(column); } int startIndex = 1; while (rs.next() && startIndex <= 50000) { int index = 0; startIndex++; Map<String, Object> rowMap = new HashMap<String, Object>(); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); String columnLabel = column.getColumnLabel(); String columnName = column.getColumnName(); if (StringUtils.isEmpty(columnName)) { columnName = column.getColumnLabel(); } columnName = columnName.toLowerCase(); String javaType = column.getJavaType(); index = index + 1; if ("String".equals(javaType)) { String value = rs.getString(column.getIndex()); if (value != null) { value = value.trim(); rowMap.put(columnName, value); rowMap.put(columnLabel, value); } } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, value); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("integer:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.intValue()); rowMap.put(columnLabel, rowMap.get(columnName)); logger.debug("?:" + num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("long:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.longValue()); rowMap.put(columnLabel, num.longValue()); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(column.getIndex()); rowMap.put(columnName, d); rowMap.put(columnLabel, d); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("double:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.doubleValue()); rowMap.put(columnLabel, num.doubleValue()); logger.debug("?:" + num.doubleValue()); } } else if ("Boolean".equals(javaType)) { rowMap.put(columnName, rs.getBoolean(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Date".equals(javaType)) { rowMap.put(columnName, rs.getTimestamp(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Blob".equals(javaType)) { // ignore } else { Object value = rs.getObject(column.getIndex()); if (value != null) { if (value instanceof String) { value = (String) value.toString().trim(); } rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } } } rowMap.put("startIndex", startIndex); resultList.add(rowMap); } } logger.debug(">resultList size=" + resultList.size()); return resultList; } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } }
From source file:com.cmart.DB.CassandraDBQuery.java
protected double insertBidDB(long userID, long itemID, int quantity, double bid, double maxBid) { double price = -1.0; if (userID < 1 || itemID < 1 || quantity < 1) return price; if (bid <= 0.0 || maxBid < bid) return price; int attemptsRemaining = SQL_RETRIES; do {/*from ww w .j av a 2 s . c o m*/ Connection conn = this.getConnection(); if (conn != null) { PreparedStatement insertBidStatement = null; PreparedStatement insertMaxBidStatement = null; PreparedStatement getMaxBidStatement = null; PreparedStatement updateItemStatement = null; PreparedStatement priceItemStatement = null; try { /* * 1. get the bid for the item * 2. check to see if the new bid is more * 3. update the item with the new bid price * 4. update the maxbid table with the users bid * 5. insert to the itemprice and revitem price tables * 6. delete the old values from the itemprice and revitem price tables */ // Get maxBid item getMaxBidStatement = conn.prepareStatement( "SELECT startprice, curbid, maxbid, noofbids, currentwinner, sellerid, categoryid, pikey FROM items WHERE KEY = " + itemID); ResultSet rs = getMaxBidStatement.executeQuery(); if (rs.next()) { // Check if the item is real long sellerid = 0; try { sellerid = rs.getLong("sellerid"); } catch (Exception e) { sellerid = 0; } if (sellerid > 0) { // Insert the bid // MAKE KEY long bidKey = System.currentTimeMillis() * shortback + System.nanoTime() % shortback; insertBidStatement = conn.prepareStatement( "INSERT INTO bids (KEY, userid, itemid, quantity, bid, maxbid, biddate) " + "VALUES ('" + bidKey + "','" + userID + "','" + itemID + "','" + quantity + "','" + bid + "','" + maxBid + "','" + System.currentTimeMillis() + "') USING CONSISTENCY " + consistency); insertBidStatement.execute(); double dbCurrentBid = rs.getDouble("curbid"); double dbMaxBid = rs.getDouble("maxbid"); double dbStartPrice = rs.getDouble("startprice"); int dbNoOfBids = (int) rs.getLong("noofbids"); long currentWinner = rs.getLong("currentwinner"); long categoryid = rs.getLong("categoryid"); // Get pikey so we can update list by price Long pikey = null; try { pikey = rs.getLong("pikey"); } catch (Exception e) { } // Vals to set in the db for the new price double newPrice = dbCurrentBid; double newMaxBid = dbMaxBid; int newNoOfBids = dbNoOfBids; long newWinner = currentWinner; if (maxBid < dbStartPrice) { // Should not happen } else if (maxBid < Math.max(dbCurrentBid, dbStartPrice)) { // The bid shouldn't really be accepted, but they will lose anyway newPrice = dbCurrentBid; newMaxBid = dbMaxBid; newNoOfBids = dbNoOfBids + 1; newWinner = currentWinner; price = Math.max(dbCurrentBid, dbStartPrice); } else if (dbMaxBid == maxBid) { // New max bid is the same as old max bid, old user is still winning as they bidded first newPrice = dbMaxBid; newMaxBid = dbMaxBid; newNoOfBids = dbNoOfBids + 1; newWinner = currentWinner; price = maxBid; } else if (dbMaxBid > maxBid) { // The old max bid is greater, old user still winning by 0.01c // max bid is the same, current bid is the new bid's maxPrice+1c newPrice = maxBid + 0.01; newMaxBid = dbMaxBid; newNoOfBids = dbNoOfBids + 1; newWinner = currentWinner; price = maxBid + 0.01; } else { // Else the new bid is more, the new user is winning // The new user's bid will be the old user's max(maxBid+1c, new bid) newPrice = (bid > dbMaxBid) ? bid : (dbMaxBid + 0.01); newMaxBid = maxBid; newNoOfBids = dbNoOfBids + 1; newWinner = userID; price = (bid > dbMaxBid) ? bid : (dbMaxBid + 0.01); } // If there is a price, update the item and the max bids if (price > 0.0) { // Make the pikey for price sorting Long priceKey = ((long) (price * 1000000000000l)) + (itemID % 10000000000l); // Update the item's price updateItemStatement = conn.prepareStatement("UPDATE items USING CONSISTENCY " + consistency + " SET curbid = '" + df.format(newPrice) + "', maxbid = '" + df.format(newMaxBid) + "', noofbids = '" + newNoOfBids + "', currentwinner = '" + newWinner + "', pikey=" + priceKey + ", ts=" + System.currentTimeMillis() + " WHERE KEY=" + itemID); updateItemStatement.executeUpdate(); // Insert user's max bid insertMaxBidStatement = conn.prepareStatement( "INSERT INTO maxbids (KEY, bidkey, userid, itemid, quantity, bid, maxbid, biddate, ts) " + "VALUES ('" + userID + "_" + itemID + "','" + bidKey + "','" + userID + "','" + itemID + "','" + quantity + "','" + df.format(bid) + "','" + df.format(maxBid) + "','" + System.currentTimeMillis() + "'," + System.currentTimeMillis() + ") USING CONSISTENCY " + consistency); insertMaxBidStatement.execute(); // Insert the new price sort values //System.out.println("item " + itemID + " mod " + (itemID % 10000000000l)); //System.out.println("price " + price + " mul " + ((long) (price*1000000000000l))); //System.out.println("Got bid price key " + priceKey +", price "+price +", item:"+itemID); priceItemStatement = conn.prepareStatement( "UPDATE priceitems USING CONSISTENCY " + consistency + " SET curbid = " + price + ", categoryid=" + categoryid + ", catzero=0, itemid=" + itemID + ", pikey=" + priceKey + " WHERE KEY=" + priceKey); priceItemStatement.executeUpdate(); priceItemStatement = conn.prepareStatement("UPDATE revpriceitems USING CONSISTENCY " + consistency + " SET curbid = " + price + ", categoryid=" + categoryid + ", catzero=0, itemid=" + itemID + ", pikey=" + priceKey + " WHERE KEY=" + (Long.MAX_VALUE - priceKey)); priceItemStatement.executeUpdate(); // Delete the old item price if (pikey != null) { priceItemStatement = conn .prepareStatement("DELETE FROM priceitems WHERE KEY=" + pikey); priceItemStatement.executeUpdate(); priceItemStatement = conn.prepareStatement( "DELETE FROM revpriceitems WHERE KEY=" + (Long.MAX_VALUE - pikey)); priceItemStatement.executeUpdate(); } } } } // Close things rs.close(); attemptsRemaining = 0; } catch (CommunicationsException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (MySQLNonTransientConnectionException e) { this.forceCloseConnection(conn); this.checkConnections(); } catch (Exception e) { System.out.println("CassandraDB (insertBid): Could not get insert bid"); e.printStackTrace(); } finally { this.closeSmt(insertBidStatement); this.closeSmt(getMaxBidStatement); this.closeSmt(insertMaxBidStatement); this.closeSmt(updateItemStatement); this.closeSmt(priceItemStatement); this.closeConnection(conn); } } attemptsRemaining--; } while (attemptsRemaining >= 0); return price; }
From source file:com.gtwm.pb.model.manageData.DataManagement.java
/** * Fetch direct from the database/*from w w w .ja v a 2 s . c o m*/ */ private ChartDataInfo fetchChartData(ChartInfo chart, Map<BaseField, String> reportFilterValues) throws CantDoThatException, SQLException { Set<ChartAggregateInfo> aggregateFunctions = chart.getAggregateFunctions(); Set<ChartGroupingInfo> groupings = chart.getGroupings(); logger.debug("Chart groupings are " + groupings); List<ChartDataRowInfo> reportSummaryRows; reportSummaryRows = new LinkedList<ChartDataRowInfo>(); Connection conn = null; PreparedStatement statement = null; try { conn = this.dataSource.getConnection(); conn.setAutoCommit(false); // First, cache the set of display values for relation fields Map<ReportFieldInfo, Map<String, String>> displayLookups = new HashMap<ReportFieldInfo, Map<String, String>>(); for (ChartGroupingInfo grouping : groupings) { ReportFieldInfo groupingReportField = grouping.getGroupingReportField(); BaseField baseField = groupingReportField.getBaseField(); if (baseField instanceof RelationField) { String relatedKey = ((RelationField) baseField).getRelatedField().getInternalFieldName(); String relatedDisplay = ((RelationField) baseField).getDisplayField().getInternalFieldName(); String relatedSource = ((RelationField) baseField).getRelatedTable().getInternalTableName(); Map<String, String> displayLookup = getKeyToDisplayMapping(conn, relatedSource, relatedKey, relatedDisplay); displayLookups.put(groupingReportField, displayLookup); } } // Create some maps to store min. and max. values of each // aggregate column // These numbers can be used e.g. to scale values when charting // summary data Map<ChartAggregateInfo, Number> maxAggValues = new HashMap<ChartAggregateInfo, Number>(); Map<ChartAggregateInfo, Number> minAggValues = new HashMap<ChartAggregateInfo, Number>(); Map<ChartAggregateInfo, Number> grandTotals = new HashMap<ChartAggregateInfo, Number>(); // Also a map for working with in the loop Map<ReportFieldInfo, Date> previousDateValues = new HashMap<ReportFieldInfo, Date>(); Calendar calendar = Calendar.getInstance(); // Get database data BaseReportInfo report = chart.getReport(); ReportData.enableOptimisations(conn, report, true); statement = chart.getChartSqlPreparedStatement(conn, reportFilterValues, false); long startTime = System.currentTimeMillis(); ResultSet summaryResults = statement.executeQuery(); while (summaryResults.next()) { ChartDataRowInfo resultRow = new ChartDataRow(); int resultColumn = 0; for (ChartGroupingInfo grouping : groupings) { ReportFieldInfo groupingReportField = grouping.getGroupingReportField(); SummaryGroupingModifier groupingModifier = grouping.getGroupingModifier(); BaseField baseField = groupingReportField.getBaseField(); resultColumn++; String value = ""; DatabaseFieldType dbType = baseField.getDbType(); if (baseField instanceof RelationField) { value = summaryResults.getString(resultColumn); Map<String, String> displayLookup = displayLookups.get(groupingReportField); value = displayLookup.get(value); } else if (dbType.equals(DatabaseFieldType.TIMESTAMP)) { if (groupingModifier != null) { value = summaryResults.getString(resultColumn); } else { Date dbValue = summaryResults.getTimestamp(resultColumn); if (dbValue != null) { if (groupingReportField instanceof ReportCalcFieldInfo) { // See DateFieldDefn constructor for // format // explanation value = ((ReportCalcFieldInfo) groupingReportField).formatDate(dbValue); } else { DateField dateField = (DateField) baseField; value = (dateField.formatDate(dbValue)); if (Integer.valueOf(dateField.getDateResolution()) .equals(Calendar.DAY_OF_MONTH)) { Date previousDbValue = previousDateValues.get(groupingReportField); if (previousDbValue != null) { calendar.setTime(previousDbValue); int previousDayOfYear = calendar.get(Calendar.DAY_OF_YEAR); calendar.setTime(dbValue); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR); int difference = Math.abs(dayOfYear - previousDayOfYear); if (difference > 1) { value += " (" + (difference - 1) + " day gap)"; } } previousDateValues.put(groupingReportField, dbValue); } } } } } else if (dbType.equals(DatabaseFieldType.FLOAT)) { double floatValue = summaryResults.getDouble(resultColumn); if (baseField instanceof DecimalField) { value = ((DecimalField) baseField).formatFloat(floatValue); } else if (groupingReportField instanceof ReportCalcFieldInfo) { value = ((ReportCalcFieldInfo) groupingReportField).formatFloat(floatValue); } else { value = summaryResults.getString(resultColumn); } } else if (dbType.equals(DatabaseFieldType.BOOLEAN)) { if (summaryResults.getBoolean(resultColumn)) { value = "true"; } else { value = "false"; } } else { value = summaryResults.getString(resultColumn); } resultRow.addGroupingValue(grouping, value); } for (ChartAggregateInfo aggregateFunction : aggregateFunctions) { resultColumn++; DatabaseFieldType dbType = aggregateFunction.getReportField().getBaseField().getDbType(); Double value = null; // deal with aggregate results which are timestamps // rather than doubles if ((!aggregateFunction.getAggregateFunction().equals(AggregateFunction.COUNT)) && (dbType.equals(DatabaseFieldType.TIMESTAMP))) { java.sql.Timestamp timestampValue = summaryResults.getTimestamp(resultColumn); if (timestampValue != null) { Long longValue = timestampValue.getTime(); value = longValue.doubleValue(); } } else { value = summaryResults.getDouble(resultColumn); } if (value != null) { int precision = 1; ReportFieldInfo aggReportField = aggregateFunction.getReportField(); if (aggReportField instanceof ReportCalcFieldInfo) { DatabaseFieldType dbFieldType = ((ReportCalcFieldInfo) aggReportField).getDbType(); if (dbFieldType.equals(DatabaseFieldType.FLOAT)) { precision = ((ReportCalcFieldInfo) aggReportField).getDecimalPrecision(); } } else if (aggReportField.getBaseField() instanceof DecimalField) { precision = ((DecimalField) aggReportField.getBaseField()).getPrecision(); } Number currentGrandTotal = grandTotals.get(aggregateFunction); if (currentGrandTotal == null) { currentGrandTotal = new Double(0); } double currentGrandTotalDbl = currentGrandTotal.doubleValue() + value; grandTotals.put(aggregateFunction, Double.valueOf(currentGrandTotalDbl)); value = MathUtils.round(value, precision); resultRow.addAggregateValue(aggregateFunction, value); Number currentMin = minAggValues.get(aggregateFunction); Number currentMax = maxAggValues.get(aggregateFunction); if (currentMin == null) { minAggValues.put(aggregateFunction, value); } else if (value.doubleValue() < currentMin.doubleValue()) { minAggValues.put(aggregateFunction, value); } if (currentMax == null) { maxAggValues.put(aggregateFunction, value); } else if (value.doubleValue() > currentMax.doubleValue()) { maxAggValues.put(aggregateFunction, value); } } } reportSummaryRows.add(resultRow); } summaryResults.close(); statement.close(); ReportData.enableOptimisations(conn, report, false); float durationSecs = (System.currentTimeMillis() - startTime) / ((float) 1000); if (durationSecs > AppProperties.longSqlTime) { logger.debug("Long SELECT SQL execution time of " + durationSecs + " seconds for summary '" + chart + "', statement = " + statement); } return new ChartData(reportSummaryRows, minAggValues, maxAggValues, grandTotals); } catch (SQLException sqlex) { throw new SQLException( "Error getting report summary data " + chart + ": " + sqlex + ". SQL = " + statement); } finally { if (conn != null) { conn.close(); } } }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8DoubleDefTable.java
protected MSSBamDoubleDefBuff unpackDoubleDefResultSetToBuff(ResultSet resultSet) throws SQLException { final String S_ProcName = "unpackDoubleDefResultSetToBuff"; int idxcol = 1; String classCode = resultSet.getString(idxcol); idxcol++;//from w ww .j a va 2s.co m MSSBamDoubleDefBuff buff; if (classCode.equals("DBL")) { buff = schema.getFactoryDoubleDef().newBuff(); } else if (classCode.equals("TDBL")) { buff = schema.getFactoryTableDouble().newBuff(); } else if (classCode.equals("SDBL")) { buff = schema.getFactorySchemaDouble().newBuff(); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Unrecognized class code \"" + classCode + "\""); } buff.setRequiredId(resultSet.getLong(idxcol)); idxcol++; buff.setRequiredTenantId(resultSet.getLong(idxcol)); idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalScopeId(null); } else { buff.setOptionalScopeId(colVal); } } idxcol++; buff.setRequiredName(resultSet.getString(idxcol)); idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalShortName(null); } else { buff.setOptionalShortName(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalLabel(null); } else { buff.setOptionalLabel(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalShortDescription(null); } else { buff.setOptionalShortDescription(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalDescription(null); } else { buff.setOptionalDescription(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalAuthorId(null); } else { buff.setOptionalAuthorId(colVal); } } idxcol++; buff.setRequiredValueContainerId(resultSet.getLong(idxcol)); idxcol++; buff.setRequiredIsNullable(resultSet.getBoolean(idxcol)); idxcol++; { boolean colVal = resultSet.getBoolean(idxcol); if (resultSet.wasNull()) { buff.setOptionalGenerateId(null); } else { buff.setOptionalGenerateId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalDataScopeId(null); } else { buff.setOptionalDataScopeId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalViewAccessSecurityId(null); } else { buff.setOptionalViewAccessSecurityId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalEditAccessSecurityId(null); } else { buff.setOptionalEditAccessSecurityId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalViewAccessFrequencyId(null); } else { buff.setOptionalViewAccessFrequencyId(colVal); } } idxcol++; { short colVal = resultSet.getShort(idxcol); if (resultSet.wasNull()) { buff.setOptionalEditAccessFrequencyId(null); } else { buff.setOptionalEditAccessFrequencyId(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalPrevId(null); } else { buff.setOptionalPrevId(colVal); } } idxcol++; { long colVal = resultSet.getLong(idxcol); if (resultSet.wasNull()) { buff.setOptionalNextId(null); } else { buff.setOptionalNextId(colVal); } } idxcol++; { String colVal = resultSet.getString(idxcol); if (resultSet.wasNull()) { buff.setOptionalDbName(null); } else { buff.setOptionalDbName(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalInitValue(null); } else { buff.setOptionalInitValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalDefaultValue(null); } else { buff.setOptionalDefaultValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalMinValue(null); } else { buff.setOptionalMinValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalMaxValue(null); } else { buff.setOptionalMaxValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalNullValue(null); } else { buff.setOptionalNullValue(colVal); } } idxcol++; { double colVal = resultSet.getDouble(idxcol); if (resultSet.wasNull()) { buff.setOptionalUnknownValue(null); } else { buff.setOptionalUnknownValue(colVal); } } idxcol++; buff.setRequiredRevision(resultSet.getInt(idxcol)); return (buff); }
From source file:com.glaf.core.jdbc.QueryHelper.java
/** * @param conn//w ww .j a v a2s . c o m * ? * @param sqlExecutor * ? * @param start * 0 * @param pageSize * ? * @return */ @SuppressWarnings("unchecked") public List<Map<String, Object>> getResultList(Connection conn, SqlExecutor sqlExecutor, int start, int pageSize) { if (!DBUtils.isLegalQuerySql(sqlExecutor.getSql())) { throw new RuntimeException(" SQL statement illegal "); } List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); String sql = sqlExecutor.getSql(); PreparedStatement psmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; boolean supportsPhysicalPage = false; try { Dialect dialect = DBConfiguration.getDatabaseDialect(conn); if (dialect != null && dialect.supportsPhysicalPage()) { supportsPhysicalPage = true; sql = dialect.getLimitString(sql, start, pageSize); logger.debug("sql=" + sqlExecutor.getSql()); logger.debug(">>sql=" + sql); } psmt = conn.prepareStatement(sql); if (sqlExecutor.getParameter() != null) { List<Object> values = (List<Object>) sqlExecutor.getParameter(); JdbcUtils.fillStatement(psmt, values); logger.debug(">>values=" + values); } rs = psmt.executeQuery(); if (conf.getBoolean("useMyBatisResultHandler", false)) { resultList = this.getResults(rs); } else { rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); List<ColumnDefinition> columns = new ArrayList<ColumnDefinition>(); for (int i = 1; i <= count; i++) { int sqlType = rsmd.getColumnType(i); ColumnDefinition column = new ColumnDefinition(); column.setIndex(i); column.setColumnName(rsmd.getColumnName(i)); column.setColumnLabel(rsmd.getColumnLabel(i)); column.setJavaType(FieldType.getJavaType(sqlType)); column.setPrecision(rsmd.getPrecision(i)); column.setScale(rsmd.getScale(i)); if (column.getScale() == 0 && sqlType == Types.NUMERIC) { column.setJavaType("Long"); } column.setName(StringTools.camelStyle(column.getColumnLabel().toLowerCase())); columns.add(column); } if (!supportsPhysicalPage) { logger.debug("---------------------skipRows:" + start); this.skipRows(rs, start, pageSize); } logger.debug("---------------------columns:" + columns.size()); logger.debug("---------------------start:" + start); logger.debug("---------------------pageSize:" + pageSize); // int index = 0; while (rs.next()) { // index++; // logger.debug("---------------------row index:" + index); Map<String, Object> rowMap = new HashMap<String, Object>(); Iterator<ColumnDefinition> iterator = columns.iterator(); while (iterator.hasNext()) { ColumnDefinition column = iterator.next(); String columnLabel = column.getColumnLabel(); String columnName = column.getColumnName(); if (StringUtils.isEmpty(columnName)) { columnName = column.getColumnLabel(); } columnName = columnName.toLowerCase(); String javaType = column.getJavaType(); if ("String".equals(javaType)) { String value = rs.getString(column.getIndex()); if (value != null) { value = value.trim(); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } } else if ("Integer".equals(javaType)) { try { Integer value = rs.getInt(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("integer:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.intValue()); rowMap.put(columnLabel, rowMap.get(columnName)); logger.debug("?:" + num.intValue()); } } else if ("Long".equals(javaType)) { try { Long value = rs.getLong(column.getIndex()); rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("long:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.longValue()); rowMap.put(columnLabel, rowMap.get(columnName)); logger.debug("?:" + num.longValue()); } } else if ("Double".equals(javaType)) { try { Double d = rs.getDouble(column.getIndex()); rowMap.put(columnName, d); rowMap.put(columnLabel, rowMap.get(columnName)); } catch (Exception e) { String str = rs.getString(column.getIndex()); logger.error("double:" + str); str = StringTools.replace(str, "$", ""); str = StringTools.replace(str, "", ""); str = StringTools.replace(str, ",", ""); NumberFormat fmt = NumberFormat.getInstance(); Number num = fmt.parse(str); rowMap.put(columnName, num.doubleValue()); rowMap.put(columnLabel, rowMap.get(columnName)); logger.debug("?:" + num.doubleValue()); } } else if ("Boolean".equals(javaType)) { rowMap.put(columnName, rs.getBoolean(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Date".equals(javaType)) { rowMap.put(columnName, rs.getTimestamp(column.getIndex())); rowMap.put(columnLabel, rowMap.get(columnName)); } else if ("Blob".equals(javaType)) { } else { Object value = rs.getObject(column.getIndex()); if (value != null) { if (value instanceof String) { value = (String) value.toString().trim(); } rowMap.put(columnName, value); rowMap.put(columnLabel, rowMap.get(columnName)); } } } resultList.add(rowMap); } } logger.debug(">resultList size = " + resultList.size()); return resultList; } catch (Exception ex) { logger.error(ex); ex.printStackTrace(); throw new RuntimeException(ex); } finally { JdbcUtils.close(psmt); JdbcUtils.close(rs); } }