Example usage for java.sql ResultSet getRow

List of usage examples for java.sql ResultSet getRow

Introduction

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

Prototype

int getRow() throws SQLException;

Source Link

Document

Retrieves the current row number.

Usage

From source file:de.static_interface.reallifeplugin.module.contract.database.table.ContractUsersTable.java

@Override
public ContractUserRow[] deserialize(ResultSet rs) throws SQLException {
    int rowcount = 0;
    if (rs.last()) {
        rowcount = rs.getRow();
        rs.beforeFirst();/*from www  . ja v a2s . c  o  m*/
    }

    ContractUserRow[] rows = new ContractUserRow[rowcount];
    int i = 0;

    while (rs.next()) {
        ContractUserRow row = new ContractUserRow();
        if (hasColumn(rs, "id")) {
            row.id = rs.getInt("id");
        }
        if (hasColumn(rs, "uuid")) {
            row.uuid = UUID.fromString(rs.getString("uuid"));
        }
        rows[i] = row;
        i++;
    }
    return rows;
}

From source file:de.static_interface.reallifeplugin.module.stockmarket.database.table.StockUsersTable.java

@Override
public StockUserRow[] deserialize(ResultSet rs) throws SQLException {
    int rowcount = 0;
    if (rs.last()) {
        rowcount = rs.getRow();
        rs.beforeFirst();//from ww  w . j  a  v  a  2  s .  co  m
    }

    StockUserRow[] rows = new StockUserRow[rowcount];
    int i = 0;

    while (rs.next()) {
        StockUserRow row = new StockUserRow();
        if (hasColumn(rs, "id")) {
            row.id = rs.getInt("id");
        }
        if (hasColumn(rs, "amount")) {
            row.amount = rs.getInt("amount");
        }
        if (hasColumn(rs, "stock_id")) {
            row.stockId = rs.getInt("stock_id");
        }
        if (hasColumn(rs, "user_id")) {
            row.userId = rs.getInt("user_id");
        }
        rows[i] = row;
        i++;
    }
    return rows;
}

From source file:com.chiorichan.database.SqlTable.java

protected Object toObject(Object clz, ResultSet rs) throws SQLException {
    Validate.notNull(clz);/* w  w  w  .  j av  a2 s.co m*/
    Validate.notNull(rs);

    if (rs.getRow() == 0)
        rs.first();

    for (Field f : clz.getClass().getDeclaredFields()) {
        SqlColumn sc = f.getAnnotation(SqlColumn.class);

        try {
            if (sc != null && rs.getObject(sc.name()) != null) {
                Object obj = rs.getObject(sc.name());
                if (f.getType().equals(String.class)) {
                    f.set(clz, ObjectUtil.castToString(obj));
                } else if (obj instanceof String && (f.getType().equals(Long.class)
                        || f.getType().getSimpleName().equalsIgnoreCase("long"))) {
                    f.set(clz, Long.parseLong((String) obj));
                } else if (obj instanceof String && (f.getType().equals(Integer.class)
                        || f.getType().getSimpleName().equalsIgnoreCase("int"))) {
                    f.set(clz, Integer.parseInt((String) obj));
                } else {
                    f.set(clz, obj);
                }
            }
        } catch (IllegalArgumentException e) {
            Loader.getLogger()
                    .severe("We can't cast the value '" + rs.getObject(sc.name()) + "' from column `"
                            + sc.name() + "` with type `" + rs.getObject(sc.name()).getClass().getSimpleName()
                            + "` to FIELD `" + f.getName() + "` with type `" + f.getType() + "`.");
        } catch (IllegalAccessException e) {
            Loader.getLogger().severe("We don't have access to FIELD `" + f.getName()
                    + "`, Be sure the field has a PUBLIC modifier.");
        }
    }

    return clz;
}

From source file:de.static_interface.reallifeplugin.module.contract.database.table.ContractUserOptionsTable.java

@Override
public ContractUserOptionsRow[] deserialize(ResultSet rs) throws SQLException {
    int rowcount = 0;
    if (rs.last()) {
        rowcount = rs.getRow();
        rs.beforeFirst();//from  w  w  w  .  jav a 2 s.  c om
    }

    ContractUserOptionsRow[] rows = new ContractUserOptionsRow[rowcount];
    int i = 0;

    while (rs.next()) {
        ContractUserOptionsRow row = new ContractUserOptionsRow();
        if (hasColumn(rs, "id")) {
            row.id = rs.getInt("id");
        }
        if (hasColumn(rs, "user_id")) {
            row.userId = rs.getInt("userId");
        }
        if (hasColumn(rs, "contract_id")) {
            row.contractId = rs.getInt("contract_id");
        }
        if (hasColumn(rs, "isCreator")) {
            row.isCreator = rs.getBoolean("isCreator");
        }
        if (hasColumn(rs, "money")) {
            row.money = rs.getDouble("money");
            if (rs.wasNull()) {
                row.money = null;
            }
        }
        rows[i] = row;
        i++;
    }
    return rows;
}

From source file:de.static_interface.reallifeplugin.module.corporation.database.table.CorpsTable.java

@Override
public CorpRow[] deserialize(ResultSet rs) throws SQLException {
    int rowcount = 0;
    if (rs.last()) {
        rowcount = rs.getRow();
        rs.beforeFirst();/*  ww w  .  j a va 2  s .  co  m*/
    }

    CorpRow[] rows = new CorpRow[rowcount];
    int i = 0;

    while (rs.next()) {
        CorpRow row = new CorpRow();
        if (hasColumn(rs, "id")) {
            row.id = rs.getInt("id");
        }
        if (hasColumn(rs, "balance")) {
            row.balance = rs.getDouble("balance");
        }
        if (hasColumn(rs, "base_id")) {
            row.baseId = rs.getString("base_id");
        }
        if (hasColumn(rs, "base_world")) {
            row.baseWorld = rs.getString("base_world");
        }
        if (hasColumn(rs, "ceo_uuid")) {
            row.ceoUniqueId = UUID.fromString(rs.getString("ceo_uuid"));
        }
        if (hasColumn(rs, "corp_name")) {
            row.corpName = rs.getString("corp_name");
        }
        if (hasColumn(rs, "isdeleted")) {
            row.isDeleted = rs.getBoolean("isdeleted");
        }
        if (hasColumn(rs, "tag")) {
            row.tag = rs.getString("tag");
        }
        if (hasColumn(rs, "time")) {
            row.time = rs.getLong("time");
        }
        rows[i] = row;
        i++;
    }
    return rows;
}

From source file:com.autentia.tnt.bill.migration.support.OriginalInformationRecoverer.java

/**
 * Recupera la suma total de todos los conceptos de cada una de las facturas cuyo tipo se envia por parametro
 * @param billType tipo de factura// ww  w.  j  a va2 s .  com
 */
public static double[] getImporteFacturaOriginal(String billType) throws Exception {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    LineNumberReader file = null;
    double[] result = new double[0];

    try {
        log.info("RECOVERING IMPORTE FACTURAS " + billType + " ORIGINALES");

        // connect to database
        Class.forName(BillToBillPaymentMigration.DATABASE_DRIVER);
        con = DriverManager.getConnection(BillToBillPaymentMigration.DATABASE_CONNECTION,
                BillToBillPaymentMigration.DATABASE_USER, BillToBillPaymentMigration.DATABASE_PASS); //NOSONAR
        con.setAutoCommit(false); //DATABASE_PASS vacio.            

        String sql = "SELECT sum((bb.units*bb.amount)*(1+(bb.iva/100))) as total from Bill b left join BillBreakDown bb on b.id=bb.billId, Organization o, Project p where b.projectId = p.id and p.organizationId = o.id and b.billType= ? group by b.id order by total";

        pstmt = con.prepareStatement(sql);

        rs = pstmt.executeQuery();
        pstmt.setString(1, billType);

        rs.last();
        result = new double[rs.getRow()];
        rs.beforeFirst();
        int counter = 0;

        while (rs.next()) {
            result[counter] = rs.getDouble(1);
            log.info("\t" + result[counter]);
            counter++;
        }
        con.commit();
    } catch (Exception e) {
        log.error("FAILED: WILL BE ROLLED BACK: ", e);
        if (con != null) {
            con.rollback();
        }
    } finally {
        cierraFichero(file);
        liberaConexion(con, pstmt, rs);
    }
    return result;
}

From source file:database.DataBaseMySQL.java

public int getRowCount(ResultSet resultSet) {
    if (resultSet == null) {
        return 0;
    }//from   w w  w  .ja  v  a2 s.  co m
    try {
        resultSet.last();
        return resultSet.getRow();
    } catch (SQLException exp) {
        exp.printStackTrace();
    } finally {
        try {
            resultSet.beforeFirst();
        } catch (SQLException exp) {
            exp.printStackTrace();
        }
    }
    return 0;
}

From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.common.JdbcTransactionListener.java

public int executeSelectQuery(String sqlQuery) throws SQLException {
    Connection connection = getConnection();
    Statement st = null;/* w  w w.jav  a 2 s . c o  m*/
    int rowCount = -1;
    try {
        if (logger.isDebugEnabled())
            logger.debug("[executeSQLQuery] " + sqlQuery);
        st = connection.createStatement();
        ResultSet results = st.executeQuery(sqlQuery);
        results.last();
        rowCount = results.getRow();
        if (logger.isDebugEnabled())
            logger.debug("[executeSQLQuery] Row count: " + rowCount);
    } catch (SQLException e) {
        logger.error("[executeSQLQuery]", e);
        throw (e);
    } finally {
        if (st != null) {
            try {
                st.close();
            } catch (SQLException e) {
                logger.error("[executeSQLQuery]", e);
            }
            st = null;
        }
    }

    return rowCount;
}

From source file:com.laxser.blitz.lama.provider.jdbc.PreparedStatementCallbackReturnId.java

@Override
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {

    if (setter != null) {
        setter.setValues(ps);/*from  ww  w . j a v  a2  s . c  o  m*/
    }

    int updated = ps.executeUpdate();
    if (updated == 0) {
        if (returnType.isArray()) {
            return Array.newInstance(wrappedIdType, 0);
        } else {
            return defaultValueOf(wrappedIdType);
        }
    }

    ResultSet keys = ps.getGeneratedKeys();
    if (keys != null) {
        try {
            Object ret = null;
            if (returnType.isArray()) {
                keys.last();
                int length = keys.getRow();
                keys.beforeFirst();
                ret = Array.newInstance(wrappedIdType, length);
            }

            for (int i = 0; keys.next(); i++) {
                Object value = mapper.mapRow(keys, i);
                if (value == null && idType.isPrimitive()) {
                    // ?primitive??null??
                    value = defaultValueOf(wrappedIdType);
                }
                if (ret != null) {
                    Array.set(ret, i + 1, value);
                } else {
                    ret = value;
                    break;
                }
            }
            return ret;
        } finally {
            JdbcUtils.closeResultSet(keys);
        }
    } else {
        if (returnType.isArray()) {
            return Array.newInstance(wrappedIdType, 0);
        } else {
            return defaultValueOf(wrappedIdType);
        }
    }
}

From source file:com.imagelake.control.PaymentPreferenceDAOImp.java

public int getResultSetCount(ResultSet rs) {
    int con = 0;//from w  ww. j a va2s .  c om
    try {
        rs.last();
        con = rs.getRow();
        rs.beforeFirst();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return con;
}