Example usage for java.sql ResultSet getInt

List of usage examples for java.sql ResultSet getInt

Introduction

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

Prototype

int getInt(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java

static private int getAssetCostBeforeDisposal(final Connection conn, int assetId) throws SQLException {
    final PreparedStatement stmt = StatementFormat.prepare(conn,
            "SELECT SUM(amount) FROM fa_transaction WHERE fa_asset_id=? AND class='COST';", assetId);
    try {//from  www.ja va2  s .com
        final ResultSet rs = stmt.executeQuery();
        try {
            return rs.next() ? rs.getInt(1) : 0;
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }
}

From source file:com.nabla.dc.server.handler.fixed_asset.Asset.java

static private int getAssetDepreciationBeforeDisposal(final Connection conn, int assetId) throws SQLException {
    final PreparedStatement stmt = StatementFormat.prepare(conn,
            "SELECT SUM(amount) FROM fa_transaction WHERE fa_asset_id=? AND class='DEP';", assetId);
    try {// w w w .ja  v  a  2  s.c  o  m
        final ResultSet rs = stmt.executeQuery();
        try {
            return rs.next() ? rs.getInt(1) : 0;
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }
}

From source file:Main.java

/**
 * //from  w ww.j  a v  a 2s.c  o m
 * @param conn
 * @param table
 * @param c_name
 */
public static void updateContentVersion(Connection conn, String table, String c_name) throws Exception {
    ResultSet rs;
    Statement s;
    int v;

    s = conn.createStatement();
    rs = s.executeQuery("SELECT c_version FROM " + table + " WHERE c_name = '" + c_name + "'");
    v = 1;

    if (rs.next()) {
        v = rs.getInt(1);
        v++;
    }

    rs.close();

    s.executeUpdate("UPDATE " + table + " SET c_version = " + v + " WHERE c_name = '" + c_name + "'");
    s.close();
}

From source file:com.nabla.wapp.server.database.Database.java

/**
 * Test if a table has any data/*from   w w  w  .java2  s.c  o  m*/
 * @param conn      - database connection
 * @param tableName   - table name
 * @return success
 * @throws SQLException
 */
public static boolean isTableEmpty(final Connection conn, final String tableName) throws SQLException {
    final Statement stmt = conn.createStatement();
    try {
        final ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName + ";");
        try {
            return rs.next() && rs.getInt(1) == 0;
        } finally {
            rs.close();
        }
    } finally {
        stmt.close();
    }
}

From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java

public static void relatoriosVendas() throws SQLException, ClassNotFoundException {
    String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM FILIAL FL "
            + "INNER JOIN FUNCIONARIO FUNC ON FUNC.ID_FILIAL = FL.ID_FILIAL "
            + "INNER JOIN ALUGUEL AL ON AL.ID_FUNCIONARIO = FUNC.ID_FUNCIONARIO " + "GROUP BY FL.NOME_FILIAL";
    Connection conn = Conexoes.obterConexao();
    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery(query);

    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    while (rs.next()) {
        ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL"));
    }/*from ww w . ja  v  a 2s  .c  o m*/

    JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Aluguis", "Filiais",
            "Separadas por filiais", ds, PlotOrientation.VERTICAL, true, true, false);

    try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\vendas.png")) {
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600);
    } catch (FileNotFoundException ex) {
        System.out.println("" + ex.getMessage());
    } catch (IOException ex) {
        System.out.println("" + ex.getMessage());
    }

    //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) {
    try (OutputStream arquivo = new FileOutputStream(
            "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) {
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600);
    } catch (FileNotFoundException ex) {
        System.out.println("" + ex.getMessage());
    } catch (IOException ex) {
        System.out.println("" + ex.getMessage());
    }
}

From source file:com.freemedforms.openreact.db.DbSchema.java

/**
 * Determine if a patch has been applied yet.
 * // www .j  a  v  a 2s  . c  om
 * @param patchName
 * @return Success.
 */
public static boolean isPatchApplied(String patchName) {
    Connection c = Configuration.getConnection();

    int found = 0;

    PreparedStatement cStmt = null;
    try {
        cStmt = c.prepareStatement("SELECT COUNT(*) FROM tPatch " + " WHERE patchName = ? " + ";");
        cStmt.setString(1, patchName);

        boolean hadResults = cStmt.execute();
        if (hadResults) {
            ResultSet rs = cStmt.getResultSet();
            rs.next();
            found = rs.getInt(1);
            rs.close();
        }
    } catch (NullPointerException npe) {
        log.error("Caught NullPointerException", npe);
    } catch (Throwable e) {
    } finally {
        DbUtil.closeSafely(cStmt);
        DbUtil.closeSafely(c);
    }

    return (boolean) (found > 0);
}

From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java

public static void relatoriosDisponibilidade() throws SQLException, ClassNotFoundException {
    String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM CARRO CA "
            + "INNER JOIN FILIAL FL ON FL.ID_FILIAL = CA.ID_FILIAL " + "WHERE CA.DISPONIBILIDADE_CARRO = '1' "
            + "GROUP BY FL.NOME_FILIAL";
    Connection conn = Conexoes.obterConexao();
    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery(query);

    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    while (rs.next()) {
        ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL"));
    }/*from   w  w w  .ja v  a  2  s. com*/

    /*File fg = new File("C:\\Users\\bruno.lopes.KRONMED\\Documents\\NetBeansProjects\\LoCarSys\\src\\main\\webapp\\ImagensLoCarSys\\disponibilidade.png");
     fg.delete();*/
    JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Disponibilidade", "Filiais",
            "Separados por filiais", ds, PlotOrientation.VERTICAL, true, true, false);

    //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) {
    try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\disponibilidade.png")) {
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600);
    } catch (FileNotFoundException ex) {
        System.out.println("" + ex.getMessage());
    } catch (IOException ex) {
        System.out.println("" + ex.getMessage());
    }

    //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) {
    try (OutputStream arquivo = new FileOutputStream(
            "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) {
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600);
    } catch (FileNotFoundException ex) {
        System.out.println("" + ex.getMessage());
    } catch (IOException ex) {
        System.out.println("" + ex.getMessage());
    }
}

From source file:Emporium.Controle.ContrDestinatarioImporta.java

public static int inserir(int idCliente, int idDepartamento, String nome, String cpf_cnpj, String empresa,
        String cep, String endereco, String numero, String complemento, String bairro, String cidade, String uf,
        String email, String celular, String pais, String nomeBD, String tags) {
    Connection conn = Conexao.conectar(nomeBD);
    String sql = "INSERT INTO cliente_destinatario (idCliente, nome, cpf_cnpj, empresa, cep, endereco, numero, complemento, bairro, cidade, uf, email, celular, pais, tags, idDepartamento) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    //System.out.println("inserir Destinatario -----------------\n"+sql+"\n---------------");

    try {/*  ww w .ja va2 s .c  om*/
        PreparedStatement valores = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        valores.setInt(1, idCliente);
        valores.setString(2, FormataString.removeSpecialChars(nome));
        valores.setString(3, cpf_cnpj);
        valores.setString(4, empresa);
        valores.setString(5, cep);
        valores.setString(6, FormataString.removeSpecialChars(endereco));
        valores.setString(7, numero);
        valores.setString(8, complemento);
        valores.setString(9, bairro);
        valores.setString(10, cidade);
        valores.setString(11, uf);
        valores.setString(12, email);
        valores.setString(13, celular);
        valores.setString(14, pais);
        valores.setString(15, tags);
        valores.setInt(16, idDepartamento);
        valores.executeUpdate();
        int autoIncrementKey = 0;
        ResultSet rs = valores.getGeneratedKeys();
        if (rs.next()) {
            autoIncrementKey = rs.getInt(1);
        }
        valores.close();
        return autoIncrementKey;
    } catch (SQLException e) {
        //System.out.println("ERRO > "+e);
        ContrErroLog.inserir("HOITO - ContrPreVendaDest.inserir", "SQLException", sql, e.toString());
        return 0;
    } finally {
        Conexao.desconectar(conn);
    }
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java

/**
 * /* ww w.ja  va2s  .c  o m*/
 *
 * @param mappedStatement mapped
 * @param parameterObject ?
 * @param boundSql boundSql
 * @param dialect database dialect
 * @return 
 * @throws java.sql.SQLException sql
 */
public static int getCount(String sql, final MappedStatement mappedStatement, final Transaction transaction,
        final Object parameterObject, final BoundSql boundSql, Dialect dialect) throws SQLException {
    final String countSql = dialect.getCountString(sql);
    if (logger.isDebugEnabled()) {
        logger.debug("Total count SQL [{}] ", countSql);
        logger.debug("Total count Parameters: {} ", parameterObject);
    }
    Connection connection = transaction.getConnection();
    PreparedStatement countStmt = connection.prepareStatement(countSql);
    DefaultParameterHandler handler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
    handler.setParameters(countStmt);

    ResultSet rs = countStmt.executeQuery();
    int count = 0;
    if (rs.next()) {
        count = rs.getInt(1);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Total count: {}", count);
    }
    return count;

}

From source file:RSMetaData.java

public static void getData(ResultSet rs, int type, int colIdx) throws SQLException {
    switch (type) {
    case java.sql.Types.CHAR:
    case java.sql.Types.VARCHAR:
        System.out.println(rs.getString(colIdx));
        break;//from   w w  w . ja  v a2 s  .c o m

    case java.sql.Types.INTEGER:
        int i = rs.getInt(colIdx);
        System.out.println(i);
        break;

    case java.sql.Types.NUMERIC:
        BigDecimal bd = rs.getBigDecimal(colIdx);
        System.out.println(bd.toString());
        break;

    case java.sql.Types.TIMESTAMP:
    case java.sql.Types.DATE:
        java.sql.Date d = rs.getDate(colIdx);
        System.out.println(d.toString());
        break;

    }
}