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:mom.trd.opentheso.bdd.helper.FacetHelper.java

/**
 * Cette fonction permet de savoir s'il a une traduction dans cette langue 
 * /*  w w w .j  a v a 2 s  .c om*/
 * @param ds
 * @param idFacet
 * @param idThesaurus
 * @param idLang
 * @return Objet class NodeConceptTree
 */
public boolean isTraductionExistOfFacet(HikariDataSource ds, int idFacet, String idThesaurus, String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id from node_label" + " where" + " facet_id = " + idFacet
                        + " and lang = '" + idLang + "'" + " and id_thesaurus = '" + idThesaurus + "'";

                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    resultSet.next();
                    if (resultSet.getRow() == 0) {
                        existe = false;
                    } else {
                        existe = true;
                    }
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if Traduction of Facet exist : " + idFacet, sqle);
    }
    return existe;
}

From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java

/**
 * Cette fonction permet de savoir si le thesaurus existe ou non
 *
 * @param conn// ww w  .ja v  a2  s  . c  o  m
 * @param idThesaurus
 * @return boolean
 */
public boolean isThesaurusExiste(Connection conn, String idThesaurus) {

    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_thesaurus from thesaurus where " + " id_thesaurus = '" + idThesaurus
                        + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getRow() != 0;
                }

            } finally {
                stmt.close();
            }
        } finally {
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if thesaurus exist : " + idThesaurus, sqle);
    }
    return existe;
}

From source file:computer_store.GUI.java

private void fillSysTable(javax.swing.JTable table, java.sql.ResultSet rs) {
    try {/* w  w w .java2 s  . c o  m*/

        //To remove previously added rows
        while (table.getRowCount() > 0) {
            ((javax.swing.table.DefaultTableModel) table.getModel()).removeRow(0);
        }
        int columns = rs.getMetaData().getColumnCount();
        int rows = 0;
        //Adding column headers
        Object[] ids = new Object[columns];
        for (int i = 1; i <= columns; i++) {
            ids[i - 1] = rs.getMetaData().getColumnName(i);
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).setColumnIdentifiers(ids);
        java.util.ArrayList<String> systems = new java.util.ArrayList();
        //Adding rows from ResultSet
        while (rs.next()) {
            systems.add(rs.getString(1));
            Object[] row = new Object[columns];
            for (int i = 1; i <= columns; i++) {
                row[i - 1] = rs.getObject(i);
            }
            ((javax.swing.table.DefaultTableModel) table.getModel()).insertRow(rs.getRow() - 1, row);
            rows++;
        }
        //Adding new column with prices
        Object[] prices = new Object[rows];
        for (int i = 0; i < prices.length; i++) {
            prices[i] = handler.getSystemPrice(systems.get(i));
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Price", prices);
        //Adding new column with selling prices
        Object[] sellPrices = new Object[rows];
        for (int i = 0; i < sellPrices.length; i++) {
            sellPrices[i] = handler.getSystemSellPrice(systems.get(i));
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Selling price", sellPrices);
        //Adding new column with current stock
        Object[] inStock = new Object[rows];
        for (int i = 0; i < prices.length; i++) {
            inStock[i] = handler.systemsInStock(systems.get(i));
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("In stock", inStock);

        rs.close();
    } catch (Exception e) {
        System.out.print(e);
    }
}

From source file:com.clustercontrol.sql.factory.RunMonitorSqlString.java

/**
 * SQL?/*from   ww  w  . j a va2 s  .co m*/
 * 
 * @param facilityId ID
 * @return ???????true
 */
@Override
public boolean collect(String facilityId) {
    // set Generation Date
    if (m_now != null) {
        m_nodeDate = m_now.getTime();
    }

    boolean result = false;

    AccessDB access = null;
    ResultSet rSet = null;

    String url = m_url;

    try {
        // ???URL??
        if (nodeInfo != null && nodeInfo.containsKey(facilityId)) {
            Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId));
            StringBinder strbinder = new StringBinder(nodeParameter);
            url = strbinder.bindParam(m_url);
            if (m_log.isTraceEnabled())
                m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId
                        + ", url = " + url + ")");
        }

        // DB??
        access = new AccessDB(m_jdbcDriver, url, m_user, m_password);

        // SQL?????
        if (m_query.length() >= 6) {
            String work = m_query.substring(0, 6);
            if (work.equalsIgnoreCase("SELECT")) {
                rSet = access.read(m_query);

                //1?1??
                rSet.first();
                m_value = rSet.getString(1);

                //?
                rSet.last();
                int number = rSet.getRow();

                NumberFormat numberFormat = NumberFormat.getNumberInstance();
                m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + m_value + ", "
                        + MessageConstant.RECORDS_NUMBER.getMessage() + " : " + numberFormat.format(number);
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;

                result = true;
            } else {
                //SELECT?
                m_log.info("collect(): "
                        + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
                m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
                m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
            }
        } else {
            //SELECT?
            m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
            m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
            m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
            m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
        }
    } catch (ClassNotFoundException e) {
        m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } catch (SQLException e) {
        // SQL
        m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } finally {
        try {
            if (rSet != null) {
                rSet.close();
            }
            if (access != null) {
                // DB?
                access.terminate();
            }
        } catch (SQLException e) {
            m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }
    return result;
}

From source file:computer_store.GUI.java

private void fillCompTable(javax.swing.JTable table, java.sql.ResultSet rs) {
    try {/*www  .  j  a  v  a2 s.c o m*/

        //To remove previously added rows
        while (table.getRowCount() > 0) {
            ((javax.swing.table.DefaultTableModel) table.getModel()).removeRow(0);
        }
        int columns = rs.getMetaData().getColumnCount();
        int rows = 0;
        java.util.ArrayList<String> helper = new java.util.ArrayList();
        //Adding column titles
        Object[] ids = new Object[columns];
        for (int i = 1; i <= columns; i++) {
            ids[i - 1] = rs.getMetaData().getColumnName(i);
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).setColumnIdentifiers(ids);
        //Adding rows from ResultSet to table model.
        while (rs.next()) {
            helper.add(rs.getString("name"));
            rows++;
            Object[] row = new Object[columns];
            for (int i = 1; i <= columns; i++) {
                row[i - 1] = rs.getObject(i);
            }
            ((javax.swing.table.DefaultTableModel) table.getModel()).insertRow(rs.getRow() - 1, row);
        }

        //Adding new column with restock numbers            
        Object[] restock = new Object[rows];
        for (int i = 0; i < restock.length; i++) {
            restock[i] = handler.getCompRestock(helper.get(i));
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("# to Restock", restock);
        //Adding selling prices
        Object[] sellPrice = new Object[rows];
        for (int i = 0; i < sellPrice.length; i++) {
            sellPrice[i] = ((int) jTable1.getValueAt(i, 1)) * 1.3;
        }
        ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Selling price", sellPrice);

        rs.close();
    } catch (Exception e) {
        System.out.print(e);
    }
}

From source file:com.comcast.oscar.dictionary.DictionarySQLQueries.java

/**
 * //  w w w.  j av a2  s . c  o m
 * @param iRowID
        
 * @return boolean
 */
private boolean checkForChild(Integer iRowID) {

    boolean localDebug = Boolean.FALSE;

    boolean foundChild = true;

    Statement parentCheckStatement = null;

    ResultSet resultSetParentCheck = null;

    // This query will check for child rows that belong to a parent row
    String sqlQuery = "SELECT " + "   ID ," + "   TYPE ," + "   TLV_NAME," + "   PARENT_ID " + "FROM "
            + this.sDictionaryTableName + " WHERE " + " PARENT_ID = '" + iRowID + "'";

    if (debug | localDebug)
        System.out.println("DictionarySQLQueries.checkForChild() -> SQL: " + sqlQuery);

    try {
        parentCheckStatement = commSqlConnection.createStatement();

        resultSetParentCheck = parentCheckStatement.executeQuery(sqlQuery);

        resultSetParentCheck.next();

        if (resultSetParentCheck.getRow() == 0) {
            if (debug | localDebug)
                System.out.println(
                        "DictionarySQLQueries.checkForChild() -> NO-CHILD-FOUND FOR ROW-ID: " + iRowID);
            return false;
        } else {
            if (debug | localDebug)
                System.out.println(
                        "DictionarySQLQueries.checkForChild() -> NO-CHILD-FOUND FOR ROW-ID: " + iRowID);
        }

    } catch (SQLException e) {

        e.printStackTrace();
    }

    return foundChild;
}

From source file:com.commander4j.db.JDBDespatch.java

public Boolean isPalletBatchStatusOK(String despatchNo) {
    Boolean result = true;/*from   w ww  .j  ava2  s .c o m*/
    String temp = Common.hostList.getHost(getHostID()).getSqlstatements()
            .getSQL("JDBDespatch.checkPalletBatchStatus");

    // Replace Despatch No

    temp = StringUtils.replace(temp, "%1", "'" + despatchNo + "'");

    // Replace Valid Pallet Status List

    String ps = lt.getPermittedPalletStatus();

    String[] split = StringUtils.split(ps, '^');

    String l = "";

    for (int cur = 0; cur < split.length; cur++) {
        l = l + "'" + split[cur] + "'";

        if (cur < (split.length - 1)) {
            l = l + ",";
        }
    }

    temp = StringUtils.replace(temp, "%2", l);

    // Replace Valid Batch Status List

    ps = lt.getPermittedBatchStatus();

    split = StringUtils.split(ps, '^');

    l = "";

    for (int cur = 0; cur < split.length; cur++) {
        l = l + "'" + split[cur] + "'";

        if (cur < (split.length - 1)) {
            l = l + ",";
        }
    }

    temp = StringUtils.replace(temp, "%3", l);

    PreparedStatement stmt = null;
    ResultSet rs;

    try {
        stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()).prepareStatement(temp);
        stmt.setFetchSize(50);

        rs = stmt.executeQuery();

        rs.last();
        int rows = rs.getRow();
        rs.beforeFirst();

        if (rows > 0) {
            result = false;
        }

        rs.close();

        stmt.close();
    } catch (SQLException e) {
        setErrorMessage(e.getMessage());
    }

    return result;
}

From source file:com.clustercontrol.sql.factory.RunMonitorSql.java

/**
 * SQL?// ww  w  .  ja v  a 2  s.c  o m
 * 
 * @param facilityId ID
 * @return ???????true
 */
@Override
public boolean collect(String facilityId) {
    // set Generation Date
    if (m_now != null) {
        m_nodeDate = m_now.getTime();
    }

    boolean result = false;

    AccessDB access = null;
    ResultSet rSet = null;

    String url = m_url;

    try {
        // ???URL??
        if (nodeInfo != null && nodeInfo.containsKey(facilityId)) {
            Map<String, String> nodeParameter = RepositoryUtil.createNodeParameter(nodeInfo.get(facilityId));
            StringBinder strbinder = new StringBinder(nodeParameter);
            url = strbinder.bindParam(m_url);
            if (m_log.isTraceEnabled())
                m_log.trace("jdbc request. (nodeInfo = " + nodeInfo + ", facilityId = " + facilityId
                        + ", url = " + url + ")");
        }

        // DB??
        access = new AccessDB(m_jdbcDriver, url, m_user, m_password);

        // SQL?????
        if (m_query.length() >= 6) {
            String work = m_query.substring(0, 6);
            if (work.equalsIgnoreCase("SELECT")) {
                rSet = access.read(m_query);

                //1?1??
                rSet.first();
                double count = rSet.getDouble(1);
                m_value = count;

                //?
                rSet.last();
                int number = rSet.getRow();

                NumberFormat numberFormat = NumberFormat.getNumberInstance();
                m_message = MessageConstant.SELECT_VALUE.getMessage() + " : " + m_value;
                m_messageOrg = MessageConstant.RECORD_VALUE.getMessage() + " : " + numberFormat.format(m_value)
                        + ", " + MessageConstant.RECORDS_NUMBER.getMessage() + " : "
                        + numberFormat.format(number);
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;

                result = true;
            } else {
                //SELECT?
                m_log.info("collect(): "
                        + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
                m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
                m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
                m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
            }
        } else {
            //SELECT?
            m_log.info("collect(): " + MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage());
            m_unKnownMessage = MessageConstant.MESSAGE_PLEASE_SET_SELECT_STATEMENT_IN_SQL.getMessage();
            m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query;
            m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
        }
    } catch (ClassNotFoundException e) {
        m_log.debug("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_CANNOT_FIND_JDBC_DRIVER.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } catch (SQLException e) {
        // SQL
        m_log.info("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
        m_unKnownMessage = MessageConstant.MESSAGE_FAILED_TO_EXECUTE_SQL.getMessage();
        m_messageOrg = MessageConstant.SQL_STRING.getMessage() + " : " + m_query + " (" + e.getMessage() + ")";
        m_messageOrg += "\n" + MessageConstant.CONNECTION_URL.getMessage() + " : " + url;
    } finally {
        try {
            if (rSet != null) {
                rSet.close();
            }
            if (access != null) {
                // DB?
                access.terminate();
            }
        } catch (SQLException e) {
            m_log.warn("collect() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }
    return result;
}

From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java

/**
 * Cette fonction permet de savoir si le thesaurus existe ou non
 *
 * @param ds/*from  w  ww. ja v  a2s .  c  o m*/
 * @param idThesaurus
 * @return boolean
 */
public boolean isThesaurusExiste(HikariDataSource ds, String idThesaurus) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_thesaurus from thesaurus where " + " id_thesaurus = '" + idThesaurus
                        + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet.next()) {
                    existe = resultSet.getRow() != 0;
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if thesaurus exist : " + idThesaurus, sqle);
    }
    return existe;
}

From source file:mom.trd.opentheso.bdd.helper.ThesaurusHelper.java

/**
 * Cette fonction permet de savoir si le terme existe ou non
 *
 * @param ds//from  w  w w.j  a v a 2 s  . c  om
 * @param idThesaurus
 * @param idLang
 * @return boolean
 */
public boolean isLanguageExistOfThesaurus(HikariDataSource ds, String idThesaurus, String idLang) {

    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    boolean existe = false;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_thesaurus from thesaurus_label where " + " id_thesaurus ='"
                        + idThesaurus + "'" + " and lang = '" + idLang + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();

                resultSet.next();
                if (resultSet.getRow() == 0) {
                    existe = false;
                } else {
                    existe = true;
                }

            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while asking if Language exist of Thesaurus : " + idThesaurus, sqle);
    }
    return existe;
}