Example usage for java.sql ResultSet getDouble

List of usage examples for java.sql ResultSet getDouble

Introduction

In this page you can find the example usage for java.sql ResultSet getDouble.

Prototype

double getDouble(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a double in the Java programming language.

Usage

From source file:au.com.ish.derbydump.derbydump.metadata.Column.java

/**
 * Get a string value for the value in this column in the datarow
 * /* w  w w. java  2s  .com*/
 * @param dataRow The row which we are exporting
 * @return an SQL statement compliant string version of the value
 */
public String toString(ResultSet dataRow) throws SQLException {

    switch (getColumnDataType()) {
    case Types.BINARY:
    case Types.VARBINARY:
    case Types.BLOB: {
        Blob obj = dataRow.getBlob(columnName);
        return (obj == null) ? "NULL" : processBinaryData(obj);
    }

    case Types.CLOB: {
        Clob obj = dataRow.getClob(columnName);
        return (obj == null) ? "NULL" : processClobData(obj);
    }

    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.VARCHAR: {
        String obj = dataRow.getString(columnName);
        return (obj == null) ? "NULL" : processStringData(obj);
    }

    case Types.TIME: {
        Time obj = dataRow.getTime(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.DATE: {
        Date obj = dataRow.getDate(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.TIMESTAMP: {
        Timestamp obj = dataRow.getTimestamp(columnName);
        return (obj == null) ? "NULL" : processStringData(obj.toString());
    }

    case Types.SMALLINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.BIGINT: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.INTEGER: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }

    case Types.NUMERIC:
    case Types.DECIMAL: {
        BigDecimal obj = dataRow.getBigDecimal(columnName);
        return (obj == null) ? "NULL" : String.valueOf(obj);
    }

    case Types.REAL:
    case Types.FLOAT: {
        Float obj = dataRow.getFloat(columnName);
        // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    case Types.DOUBLE: {
        Double obj = dataRow.getDouble(columnName);
        return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj);
    }

    default: {
        Object obj = dataRow.getObject(columnName);
        return (obj == null) ? "NULL" : obj.toString();
    }
    }
}

From source file:org.agnitas.util.AgnUtils.java

/**
 * Getter for property bshInterpreter./*  w w w. j  ava 2s  .  co m*/
 *
 * @return Value of property bshInterpreter.
 */
public static Interpreter getBshInterpreter(int cID, int customerID, ApplicationContext con) {
    DataSource ds = (DataSource) con.getBean("dataSource");
    Interpreter aBsh = new Interpreter();
    NameSpace aNameSpace = aBsh.getNameSpace();
    aNameSpace.importClass("org.agnitas.util.AgnUtils");

    String sqlStatement = "select * from customer_" + cID + "_tbl cust where cust.customer_id=" + customerID;
    Connection dbCon = DataSourceUtils.getConnection(ds);

    try {
        Statement stmt = dbCon.createStatement();
        ResultSet rset = stmt.executeQuery(sqlStatement);
        ResultSetMetaData aMeta = rset.getMetaData();

        if (rset.next()) {
            for (int i = 1; i <= aMeta.getColumnCount(); i++) {
                switch (aMeta.getColumnType(i)) {
                case java.sql.Types.BIGINT:
                case java.sql.Types.INTEGER:
                case java.sql.Types.NUMERIC:
                case java.sql.Types.SMALLINT:
                case java.sql.Types.TINYINT:
                    if (rset.getObject(i) != null) {
                        aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.lang.Integer.class,
                                new Integer(rset.getInt(i)), null);
                    } else {
                        aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.lang.Integer.class, null,
                                null);
                    }
                    break;

                case java.sql.Types.DECIMAL:
                case java.sql.Types.DOUBLE:
                case java.sql.Types.FLOAT:
                    if (rset.getObject(i) != null) {
                        aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.lang.Double.class,
                                new Double(rset.getDouble(i)), null);
                    } else {
                        aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.lang.Double.class, null, null);
                    }
                    break;

                case java.sql.Types.CHAR:
                case java.sql.Types.LONGVARCHAR:
                case java.sql.Types.VARCHAR:
                    aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.lang.String.class,
                            rset.getString(i), null);
                    break;

                case java.sql.Types.DATE:
                case java.sql.Types.TIME:
                case java.sql.Types.TIMESTAMP:
                    aNameSpace.setTypedVariable(aMeta.getColumnName(i), java.util.Date.class,
                            rset.getTimestamp(i), null);
                    break;
                default:
                    logger.error("Ignoring: " + aMeta.getColumnName(i));
                }
            }
        }
        rset.close();
        stmt.close();
        // add virtual column "sysdate"
        aNameSpace.setTypedVariable(AgnUtils.getHibernateDialect().getCurrentTimestampSQLFunctionName(),
                Date.class, new Date(), null);
    } catch (Exception e) {
        sendExceptionMail("Sql: " + sqlStatement, e);
        logger.error("getBshInterpreter: " + e.getMessage());
        aBsh = null;
    }
    DataSourceUtils.releaseConnection(dbCon, ds);
    return aBsh;
}

From source file:com.jabyftw.lobstercraft.player.PlayerHandlerService.java

/**
 * This method will cache every registered player. Should run on start, so we don't need to synchronize it.
 *
 * @param connection MySQL connection// w  ww.  j  a  v  a  2s . co  m
 * @throws SQLException in case of something going wrong, should stop the server on start
 */
private void cacheOfflinePlayers(@NotNull final Connection connection) throws SQLException {
    long start = System.nanoTime();

    // Prepare statement and execute query
    PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM minecraft.user_profiles;");
    ResultSet resultSet = preparedStatement.executeQuery();

    // Iterate through all results
    while (resultSet.next()) {
        String playerName = resultSet.getString("playerName").toLowerCase();

        // Check for the nullity of some variables
        Integer cityId = resultSet.getInt("city_cityId");
        if (resultSet.wasNull())
            cityId = null;

        Byte cityOccupationId = resultSet.getByte("cityOccupation");
        if (resultSet.wasNull())
            cityOccupationId = null;

        OfflinePlayer offlinePlayer = new OfflinePlayer(resultSet.getInt("playerId"), playerName,
                resultSet.getString("password"), resultSet.getDouble("moneyAmount"), cityId,
                CityOccupation.fromId(cityOccupationId), resultSet.getLong("lastTimeOnline"),
                resultSet.getLong("timePlayed"), resultSet.getString("lastIp"));

        registeredOfflinePlayers_name.put(playerName, offlinePlayer);
        registeredOfflinePlayers_id.put(offlinePlayer.getPlayerId(), offlinePlayer);

        // Check if player has a city
        if (offlinePlayer.getCityId() != null) {
            if (!registeredOfflinePlayers_cityId.containsKey(offlinePlayer.getCityId()))
                registeredOfflinePlayers_cityId.put(offlinePlayer.getCityId(), new HashSet<>());
            registeredOfflinePlayers_cityId.get(offlinePlayer.getCityId()).add(offlinePlayer);
        }
    }

    // Close everything
    resultSet.close();
    preparedStatement.close();

    // Announce values
    LobsterCraft.logger.info(Util.appendStrings("Took us ",
            Util.formatDecimal(
                    (double) (System.nanoTime() - start) / (double) TimeUnit.MILLISECONDS.toNanos(1)),
            "ms to retrieve ", registeredOfflinePlayers_id.size(), " players."));
}

From source file:com.skilrock.lms.common.db.QueryHelper.java

public List SearchCheque(String chequeNumber, long transactionId, double chequeBounceCharges)
        throws LMSException {
    List<ChequeBean> searchResults = new ArrayList<ChequeBean>();
    ResultSet resultSet = null;
    Connection connection = null;
    Statement statement = null;//  www.  jav  a  2s .  c  o  m

    try {
        connection = DBConnect.getConnection();
        statement = connection.createStatement();
        String orgCodeQry = " b.name orgCode ";

        if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE")) {
            orgCodeQry = " b.org_code orgCode ";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE_NAME")) {
            orgCodeQry = " concat(b.org_code,'_',b.name)  orgCode";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("NAME_CODE")) {
            orgCodeQry = " concat(b.name,'_',b.org_code)  orgCode ";

        }
        String query = "select a.transaction_id,a.cheque_nbr,a.cheque_date,a.issuing_party_name,a.drawee_bank,a.cheque_amt,"
                + orgCodeQry
                + ",b.organization_id  from st_lms_bo_sale_chq a, st_lms_organization_master b  where a.cheque_nbr ="
                + chequeNumber + " and a.agent_org_id =b.organization_id and a.transaction_id=" + transactionId;

        logger.debug("-----Query----::" + query);
        // ResultSet resultSet = statement.executeQuery(query);

        resultSet = statement.executeQuery(query);

        ChequeBean chequeBean = new ChequeBean();
        while (resultSet.next()) {
            chequeBean.setChequeNumber(resultSet.getString(TableConstants.CHEQUE_NUMBER));
            chequeBean.setChequeDate(resultSet.getDate(TableConstants.CHEQUE_DATE).toString());
            chequeBean.setIssuePartyname(resultSet.getString(TableConstants.ISSUE_PARTY_NAME));
            chequeBean.setBankName(resultSet.getString(TableConstants.DRAWEE_BANK));
            chequeBean.setChequeAmount(resultSet.getDouble(TableConstants.CHEQUE_AMT));
            chequeBean.setOrgName(resultSet.getString("orgCode"));
            chequeBean.setOrgId(resultSet.getInt("organization_id"));
            chequeBean.setTransactionId(resultSet.getLong(TableConstants.TRANSACTION_ID));
            // chequeBean.setChequeBounceCharges(chequeBounceCharges);
            searchResults.add(chequeBean);

        }
    }

    catch (SQLException e) {

        e.printStackTrace();
        throw new LMSException(e);
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ee) {
            logger.error("Error in closing the Connection");
            ee.printStackTrace();
            throw new LMSException(ee);

        }

    }

    return searchResults;

}

From source file:com.skilrock.lms.common.db.QueryHelper.java

public List<ChequeBean> SearchChequeRetailer(String chequeNumber, long transactionId,
        double chequeBounceCharges) throws LMSException {
    List<ChequeBean> searchResults = new ArrayList<ChequeBean>();

    ResultSet resultSet = null;
    Connection connection = null;
    Statement statement = null;//from w w  w. j a  v  a2  s  .co m
    try {
        connection = DBConnect.getConnection();
        statement = connection.createStatement();
        String orgCodeQry = " b.name orgCode ";

        if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE")) {
            orgCodeQry = " b.org_code orgCode ";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE_NAME")) {
            orgCodeQry = " concat(b.org_code,'_',b.name)  orgCode";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("NAME_CODE")) {
            orgCodeQry = " concat(b.name,'_',b.org_code)  orgCode ";

        }
        String query = "select a.transaction_id,a.cheque_nbr,a.cheque_date,a.issuing_party_name,a.drawee_bank,a.cheque_amt,"
                + orgCodeQry
                + ",b.organization_id from st_lms_agent_sale_chq a, st_lms_organization_master b  where a.cheque_nbr ="
                + chequeNumber + " and a.retailer_org_id =b.organization_id and a.transaction_id="
                + transactionId;

        logger.debug("-----Query----::" + query);
        // ResultSet resultSet = statement.executeQuery(query);

        resultSet = statement.executeQuery(query);

        ChequeBean chequeBean = new ChequeBean();
        while (resultSet.next()) {
            chequeBean.setChequeNumber(resultSet.getString("cheque_nbr"));
            chequeBean.setChequeDate(resultSet.getDate(TableConstants.CHEQUE_DATE).toString());
            chequeBean.setIssuePartyname(resultSet.getString(TableConstants.ISSUE_PARTY_NAME));
            chequeBean.setBankName(resultSet.getString(TableConstants.DRAWEE_BANK));
            chequeBean.setChequeAmount(resultSet.getDouble(TableConstants.CHEQUE_AMT));
            //chequeBean.setOrgName(resultSet.getString(TableConstants.NAME));
            chequeBean.setOrgName(resultSet.getString("orgCode"));
            chequeBean.setOrgId(resultSet.getInt("organization_id"));
            chequeBean.setTransactionId(resultSet.getLong(TableConstants.TRANSACTION_ID));
            // chequeBean.setChequeBounceCharges(chequeBounceCharges);
            searchResults.add(chequeBean);

        }
    }

    catch (SQLException e) {

        e.printStackTrace();
        throw new LMSException(e);
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ee) {
            logger.error("Error in closing the Connection");
            ee.printStackTrace();
            throw new LMSException(ee);

        }

    }
    return searchResults;

}

From source file:database.DataLoader.java

private void addPaymentsToOrders() throws Exception {
    String tableName = ORDER;/*ww w  . j  a v a2  s. c o  m*/
    final ResultSet set = getFromOldBase(getSelectAll(tableName));
    final List<Payment> paymentList = getAllPayments();
    while (set.next()) {

        Long oldOrderId = 0L;
        try {
            oldOrderId = set.getLong("id");

            final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {

                @Override
                protected void doInTransactionWithoutResult(TransactionStatus ts) {
                    Long oldOrderId = 0L;
                    try {
                        oldOrderId = set.getLong("id");
                        Double prepay = set.getDouble("prepay");
                        Long newOrderId = getNewId(oldOrderId, ORDER);
                        Order order = getOrder(newOrderId);
                        if (!containsPayment(paymentList, order)) {
                            Payment payment = new Payment();
                            payment.setAmount(prepay);
                            payment.setOrder(order);
                            Date paymentDate;
                            if (order.getRealDate() != null) {
                                paymentDate = order.getRealDate();
                            } else if (order.getDeadlineDate() != null) {
                                paymentDate = order.getDeadlineDate();
                            } else if (order.getOrderDate() != null) {
                                paymentDate = order.getOrderDate();
                            } else {
                                paymentDate = new Date();
                            }
                            payment.setPaymentDate(paymentDate);
                            payment.setPaymentType(paymentTypeService.getStandartTypeFromOldDb());
                            payment.setUser(userService.getStandartAdmin());
                            if (payment.getAmount() != null && order.getCost() != null) {
                                if (payment.getAmount() >= order.getCost()) {
                                    payment.setFinalPayment(true);
                                }
                            }
                            paymentDao.save(payment);
                        }
                    } catch (Throwable e) {
                        ts.setRollbackOnly();
                        messageList
                                .add(" - " + oldOrderId + " " + StringAdapter.getStackExeption(e));
                        log.warn(" - " + oldOrderId + " " + StringAdapter.getStackExeption(e));
                    }
                }
            });

        } catch (Throwable e) {
            messageList.add(" - " + oldOrderId + " " + StringAdapter.getStackExeption(e));
            log.warn(" - " + oldOrderId + " " + StringAdapter.getStackExeption(e));
        }

    }
}

From source file:com.skilrock.lms.coreEngine.accMgmt.common.SearchChequeHelper.java

/**
 * This method is used to search cheque which are submitted by agent.
 * /*from   w  w w  .  j  a  va2  s  .co  m*/
 * @param searchMap
 * @return List of Cheques
 * @throws LMSException
 */
public List<ChequeBean> searchCheque(Map searchMap) throws LMSException {

    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    logger.debug("-----Query----::");
    try {

        ChequeBean chequeBean = null;
        List<ChequeBean> searchResults = new ArrayList<ChequeBean>();

        connection = DBConnect.getConnection();
        statement = connection.createStatement();

        String dynamicWhereClause = getWhereClause(searchMap);
        String orgCodeQry = " b.name orgCode ";

        if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE")) {
            orgCodeQry = " b.org_code orgCode ";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("CODE_NAME")) {
            orgCodeQry = " concat(b.org_code,'_',b.name)  orgCode";

        } else if ((LMSFilterDispatcher.orgFieldType).equalsIgnoreCase("NAME_CODE")) {
            orgCodeQry = " concat(b.name,'_',b.org_code)  orgCode ";

        }
        String query = "select a.transaction_id,a.cheque_nbr,a.cheque_date,a.issuing_party_name,a.drawee_bank,a.cheque_amt,"
                + orgCodeQry
                + ",b.organization_id  from st_lms_bo_sale_chq a, st_lms_organization_master b where a.agent_org_id=b.organization_id and a.transaction_type='CHEQUE' "
                + dynamicWhereClause;

        logger.debug("-----Query yogesh************----::" + query);

        resultSet = statement.executeQuery(query);

        while (resultSet.next()) {

            chequeBean = new ChequeBean();
            logger.debug("-----Query----::");

            chequeBean.setChequeNumber(resultSet.getString(TableConstants.CHEQUE_NUMBER));
            logger.debug("Cheque Date" + resultSet.getDate(TableConstants.CHEQUE_DATE));
            String sd = resultSet.getDate(TableConstants.CHEQUE_DATE).toString();
            Calendar cal = Calendar.getInstance();

            java.sql.Date sD = new java.sql.Date(cal.getTimeInMillis());

            chequeBean.setChequeDate(sd);
            chequeBean.setIssuePartyname(resultSet.getString(TableConstants.ISSUE_PARTY_NAME));
            chequeBean.setBankName(resultSet.getString(TableConstants.DRAWEE_BANK));
            chequeBean.setChequeAmount(resultSet.getDouble(TableConstants.CHEQUE_AMT));
            chequeBean.setOrgName(resultSet.getString("orgCode"));
            chequeBean.setOrgId(resultSet.getInt("organization_id"));
            chequeBean.setTransactionId(resultSet.getLong(TableConstants.TRANSACTION_ID));
            // chequeBean.setChequeBounceCharges(chequeBounceCharges);

            searchResults.add(chequeBean);

            logger.debug("Cheque Number" + resultSet.getString(TableConstants.CHEQUE_NUMBER));
            logger.debug("Org Name:" + resultSet.getString("orgCode"));
            logger.debug("Bank" + resultSet.getString(TableConstants.DRAWEE_BANK));

        }
        return searchResults;

    } catch (SQLException e) {
        logger.error("Exception: " + e);
        e.printStackTrace();
        throw new LMSException(e);
    } finally {

        try {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException se) {
            logger.error("Exception: " + se);
            throw new LMSException(se);
        }
    }

}

From source file:com.wso2telco.core.dbutils.DbService.java

public SpendLimitDAO getGroupTotalDayAmount(String groupName, String operator, String msisdn)
        throws DBUtilException {

    Connection con = null;/*from   w ww . j  a v a 2  s  .co  m*/
    PreparedStatement ps = null;
    ResultSet rs = null;
    SpendLimitDAO spendLimitDAO = null;

    try {
        con = DbUtils.getDBConnection();

        Calendar calendarFrom = Calendar.getInstance();
        calendarFrom.set(Calendar.AM_PM, Calendar.AM);
        calendarFrom.set(Calendar.HOUR, 00);
        calendarFrom.set(Calendar.MINUTE, 00);
        calendarFrom.set(Calendar.SECOND, 00);
        calendarFrom.set(Calendar.MILLISECOND, 00);

        Calendar calendarTo = Calendar.getInstance();
        calendarTo.set(Calendar.AM_PM, Calendar.PM);
        calendarTo.set(Calendar.HOUR, 11);
        calendarTo.set(Calendar.MINUTE, 59);
        calendarTo.set(Calendar.SECOND, 59);
        calendarTo.set(Calendar.MILLISECOND, 999);

        String sql = "SELECT SUM(amount) AS amount " + "FROM spendlimitdata  "
                + "where effectiveTime between ? and ? " + "and groupName=? " + "and operatorId=? "
                + "and msisdn=? " + "group by groupName, operatorId, msisdn";

        ps = con.prepareStatement(sql);

        ps.setLong(1, calendarFrom.getTimeInMillis());
        ps.setLong(2, calendarTo.getTimeInMillis());
        ps.setString(3, groupName);
        ps.setString(4, operator);
        ps.setString(5, msisdn);

        rs = ps.executeQuery();

        if (rs.next()) {
            spendLimitDAO = new SpendLimitDAO();
            spendLimitDAO.setAmount(rs.getDouble("amount"));
        }
    } catch (Exception e) {
        DbUtils.handleException("Error while checking Operator Spend Limit. ", e);
    } finally {
        DbUtils.closeAllConnections(ps, con, rs);
    }
    return spendLimitDAO;
}

From source file:com.nway.spring.jdbc.bean.AsmBeanProcessor.java

private Object processColumn(ResultSet rs, int index, Class<?> propType, String writer, String processorName,
        String beanName, MethodVisitor mv) throws SQLException {

    if (propType.equals(String.class)) {
        visitMethod(mv, index, beanName, "Ljava/lang/String;", "getString", writer);
        return rs.getString(index);
    } else if (propType.equals(Integer.TYPE)) {
        visitMethod(mv, index, beanName, "I", "getInt", writer);
        return rs.getInt(index);
    } else if (propType.equals(Integer.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_INTEGER, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Integer.class);
    } else if (propType.equals(Long.TYPE)) {
        visitMethod(mv, index, beanName, "J", "getLong", writer);
        return rs.getLong(index);
    } else if (propType.equals(Long.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_LONG, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Long.class);
    } else if (propType.equals(java.sql.Date.class)) {
        visitMethod(mv, index, beanName, "Ljava/sql/Date;", "getDate", writer);
        return rs.getDate(index);
    } else if (propType.equals(java.util.Date.class)) {
        visitMethodCast(mv, index, beanName, PROPERTY_TYPE_DATE, "java/util/Date", writer);
        return rs.getTimestamp(index);
    } else if (propType.equals(Timestamp.class)) {
        visitMethod(mv, index, beanName, "Ljava/sql/Timestamp;", "getTimestamp", writer);
        return rs.getTimestamp(index);
    } else if (propType.equals(Time.class)) {
        visitMethod(mv, index, beanName, "Ljava/sql/Time;", "getTime", writer);
        return rs.getTime(index);
    } else if (propType.equals(Double.TYPE)) {
        visitMethod(mv, index, beanName, "D", "getDouble", writer);
        return rs.getDouble(index);
    } else if (propType.equals(Double.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_DOUBLE, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Double.class);
    } else if (propType.equals(Float.TYPE)) {
        visitMethod(mv, index, beanName, "F", "getFloat", writer);
        return rs.getFloat(index);
    } else if (propType.equals(Float.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_FLOAT, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Float.class);
    } else if (propType.equals(Boolean.TYPE)) {
        visitMethod(mv, index, beanName, "Z", "getBoolean", writer);
        return rs.getBoolean(index);
    } else if (propType.equals(Boolean.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BOOLEAN, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Boolean.class);
    } else if (propType.equals(Clob.class)) {
        visitMethod(mv, index, beanName, "Ljava/sql/Clob;", "getClob", writer);
        return rs.getClob(index);
    } else if (propType.equals(Blob.class)) {
        visitMethod(mv, index, beanName, "Ljava/sql/Blob;", "getBlob", writer);
        return rs.getBlob(index);
    } else if (propType.equals(byte[].class)) {
        visitMethod(mv, index, beanName, "[B", "getBytes", writer);
        return rs.getBytes(index);
    } else if (propType.equals(Short.TYPE)) {
        visitMethod(mv, index, beanName, "S", "getShort", writer);
        return rs.getShort(index);
    } else if (propType.equals(Short.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_SHORT, writer, processorName);
        return JdbcUtils.getResultSetValue(rs, index, Short.class);
    } else if (propType.equals(Byte.TYPE)) {
        visitMethod(mv, index, beanName, "B", "getByte", writer);
        return rs.getByte(index);
    } else if (propType.equals(Byte.class)) {
        visitMethodWrap(mv, index, beanName, PROPERTY_TYPE_BYTE, writer, processorName);
        return rs.getByte(index);
    } else {// w  w w  . ja  v  a2 s  .c  o  m
        visitMethodCast(mv, index, beanName, PROPERTY_TYPE_OTHER, propType.getName().replace('.', '/'), writer);
        return rs.getObject(index);
    }
}

From source file:org.apache.bigtop.itest.hive.TestJdbc.java

@Test
public void preparedStmtAndResultSet() throws SQLException {
    final String tableName = "bigtop_jdbc_psars_test_table";
    try (Statement stmt = conn.createStatement()) {
        stmt.execute("drop table if exists " + tableName);
        stmt.execute("create table " + tableName + " (bo boolean, ti tinyint, db double, fl float, "
                + "i int, lo bigint, sh smallint, st varchar(32))");
    }/*from  w w w.  ja  v a  2 s  .  c om*/

    // NOTE Hive 1.2 theoretically support binary, Date & Timestamp in JDBC, but I get errors when I
    // try to put them in the query.
    try (PreparedStatement ps = conn
            .prepareStatement("insert into " + tableName + " values (?, ?, ?, ?, ?, ?, ?, ?)")) {
        ps.setBoolean(1, true);
        ps.setByte(2, (byte) 1);
        ps.setDouble(3, 3.141592654);
        ps.setFloat(4, 3.14f);
        ps.setInt(5, 3);
        ps.setLong(6, 10L);
        ps.setShort(7, (short) 20);
        ps.setString(8, "abc");
        ps.executeUpdate();
    }

    try (PreparedStatement ps = conn.prepareStatement("insert into " + tableName + " (i, st) " + "values(?, ?)",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
        ps.setNull(1, Types.INTEGER);
        ps.setObject(2, "mary had a little lamb");
        ps.executeUpdate();
        ps.setNull(1, Types.INTEGER, null);
        ps.setString(2, "its fleece was white as snow");
        ps.clearParameters();
        ps.setNull(1, Types.INTEGER, null);
        ps.setString(2, "its fleece was white as snow");
        ps.execute();

    }

    try (Statement stmt = conn.createStatement()) {

        ResultSet rs = stmt.executeQuery("select * from " + tableName);

        ResultSetMetaData md = rs.getMetaData();

        int colCnt = md.getColumnCount();
        LOG.debug("Column count is " + colCnt);

        for (int i = 1; i <= colCnt; i++) {
            LOG.debug("Looking at column " + i);
            String strrc = md.getColumnClassName(i);
            LOG.debug("Column class name is " + strrc);

            int intrc = md.getColumnDisplaySize(i);
            LOG.debug("Column display size is " + intrc);

            strrc = md.getColumnLabel(i);
            LOG.debug("Column label is " + strrc);

            strrc = md.getColumnName(i);
            LOG.debug("Column name is " + strrc);

            intrc = md.getColumnType(i);
            LOG.debug("Column type is " + intrc);

            strrc = md.getColumnTypeName(i);
            LOG.debug("Column type name is " + strrc);

            intrc = md.getPrecision(i);
            LOG.debug("Precision is " + intrc);

            intrc = md.getScale(i);
            LOG.debug("Scale is " + intrc);

            boolean boolrc = md.isAutoIncrement(i);
            LOG.debug("Is auto increment? " + boolrc);

            boolrc = md.isCaseSensitive(i);
            LOG.debug("Is case sensitive? " + boolrc);

            boolrc = md.isCurrency(i);
            LOG.debug("Is currency? " + boolrc);

            intrc = md.getScale(i);
            LOG.debug("Scale is " + intrc);

            intrc = md.isNullable(i);
            LOG.debug("Is nullable? " + intrc);

            boolrc = md.isReadOnly(i);
            LOG.debug("Is read only? " + boolrc);

        }

        while (rs.next()) {
            LOG.debug("bo = " + rs.getBoolean(1));
            LOG.debug("bo = " + rs.getBoolean("bo"));
            LOG.debug("ti = " + rs.getByte(2));
            LOG.debug("ti = " + rs.getByte("ti"));
            LOG.debug("db = " + rs.getDouble(3));
            LOG.debug("db = " + rs.getDouble("db"));
            LOG.debug("fl = " + rs.getFloat(4));
            LOG.debug("fl = " + rs.getFloat("fl"));
            LOG.debug("i = " + rs.getInt(5));
            LOG.debug("i = " + rs.getInt("i"));
            LOG.debug("lo = " + rs.getLong(6));
            LOG.debug("lo = " + rs.getLong("lo"));
            LOG.debug("sh = " + rs.getShort(7));
            LOG.debug("sh = " + rs.getShort("sh"));
            LOG.debug("st = " + rs.getString(8));
            LOG.debug("st = " + rs.getString("st"));
            LOG.debug("tm = " + rs.getObject(8));
            LOG.debug("tm = " + rs.getObject("st"));
            LOG.debug("tm was null " + rs.wasNull());
        }
        LOG.debug("bo is column " + rs.findColumn("bo"));

        int intrc = rs.getConcurrency();
        LOG.debug("concurrency " + intrc);

        intrc = rs.getFetchDirection();
        LOG.debug("fetch direction " + intrc);

        intrc = rs.getType();
        LOG.debug("type " + intrc);

        Statement copy = rs.getStatement();

        SQLWarning warning = rs.getWarnings();
        while (warning != null) {
            LOG.debug("Found a warning: " + warning.getMessage());
            warning = warning.getNextWarning();
        }
        rs.clearWarnings();
    }
}