Example usage for java.sql ResultSet getStatement

List of usage examples for java.sql ResultSet getStatement

Introduction

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

Prototype

Statement getStatement() throws SQLException;

Source Link

Document

Retrieves the Statement object that produced this ResultSet object.

Usage

From source file:com.runwaysdk.dataaccess.database.general.MySQL.java

/**
 * @see com.runwaysdk.dataaccess.database.relationship.AbstractDatabase#getParentCountForChild(java.lang.String,
 *      java.lang.String)// ww  w  .  ja va2 s. c o  m
 */
public long getParentCountForChild(String child_id, String relationshipTableName) {
    String query = " SELECT COUNT(*) AS CT \n" + " FROM " + relationshipTableName + " \n" + " WHERE "
            + RelationshipDAOIF.CHILD_ID_COLUMN + " = '" + child_id + "' \n" + " AND "
            + RelationshipDAOIF.PARENT_ID_COLUMN + " IN " + "   (SELECT DISTINCT "
            + RelationshipDAOIF.PARENT_ID_COLUMN + " \n" + "    FROM " + relationshipTableName + " \n"
            + "    WHERE " + RelationshipDAOIF.CHILD_ID_COLUMN + " = '" + child_id + "')";

    ResultSet resultSet = this.query(query);

    long returnValue = 0;

    try {
        if (resultSet.next()) {
            Long number = (Long) resultSet.getLong("ct");
            returnValue = number.longValue();
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return returnValue;

}

From source file:com.runwaysdk.dataaccess.database.general.SQLServer.java

@Override
public List<String> getColumnNames(String tableName) {
    String sqlStmt = "SELECT column_name AS field FROM information_schema.columns WHERE table_name = '"
            + tableName + "'";
    ResultSet resultSet = query(sqlStmt);
    LinkedList<String> columnNames = new LinkedList<String>();

    try {/*from   ww w .  j  a va 2s.  co  m*/
        while (resultSet.next()) {
            columnNames.add((String) resultSet.getString("field"));
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }
    return columnNames;
}

From source file:com.runwaysdk.dataaccess.database.general.SQLServer.java

/**
 * @see com.runwaysdk.dataaccess.database.relationship.AbstractDatabase#getChildCountForParent(java.lang.String, java.lang.String)
 *//*from w  ww  .  ja  v a2  s .  c  om*/
public long getChildCountForParent(String parent_id, String relationshipTableName) {
    String query = " SELECT COUNT(*) AS CT \n" + " FROM " + relationshipTableName + " \n" + " WHERE "
            + RelationshipDAOIF.PARENT_ID_COLUMN + " = '" + parent_id + "' \n" + " AND "
            + RelationshipDAOIF.CHILD_ID_COLUMN + " IN " + "   (SELECT DISTINCT "
            + RelationshipDAOIF.CHILD_ID_COLUMN + " \n" + "    FROM " + relationshipTableName + " \n"
            + "    WHERE " + RelationshipDAOIF.PARENT_ID_COLUMN + " = '" + parent_id + "')";

    ResultSet resultSet = this.query(query);

    long returnValue = 0;

    try {
        if (resultSet.next()) {
            Long number = (Long) resultSet.getLong("ct");
            returnValue = number.longValue();
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return returnValue;

    // Heads up:
    //    List<DynaBean> dynaBeanList = this.select(query);
    //
    //    if (dynaBeanList.size() == 0)
    //    {
    //      return 0;
    //    }
    //    else
    //    {
    //      DynaBean dynaBean = dynaBeanList.get(0);
    //      Integer number = (Integer)dynaBean.get("ct");
    //      return number.longValue();
    //    }
}

From source file:com.runwaysdk.dataaccess.database.general.SQLServer.java

/**
 * @see com.runwaysdk.dataaccess.database.relationship.AbstractDatabase#getParentCountForChild(java.lang.String, java.lang.String)
 */// w ww .  j a  v  a  2s  .  c  om
public long getParentCountForChild(String child_id, String relationshipTableName) {
    String query = " SELECT COUNT(*) AS CT \n" + " FROM " + relationshipTableName + " \n" + " WHERE "
            + RelationshipDAOIF.CHILD_ID_COLUMN + " = '" + child_id + "' \n" + " AND "
            + RelationshipDAOIF.PARENT_ID_COLUMN + " IN " + "   (SELECT DISTINCT "
            + RelationshipDAOIF.PARENT_ID_COLUMN + " \n" + "    FROM " + relationshipTableName + " \n"
            + "    WHERE " + RelationshipDAOIF.CHILD_ID_COLUMN + " = '" + child_id + "')";

    ResultSet resultSet = this.query(query);

    long returnValue = 0;

    try {
        if (resultSet.next()) {
            Long number = (Long) resultSet.getLong("ct");
            returnValue = number.longValue();
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return returnValue;

    // Heads up:
    //    List<DynaBean> dynaBeanList = this.select(query);
    //
    //    if (dynaBeanList.size() == 0)
    //    {
    //      return 0;
    //    }
    //    else
    //    {
    //      DynaBean dynaBean = dynaBeanList.get(0);
    //      Integer number = (Integer)dynaBean.get("ct");
    //      return number.longValue();
    //    }
}

From source file:com.runwaysdk.dataaccess.database.general.MySQL.java

/**
 * Returns true if the given index exists on the given table, false otherwise.
 * /*w ww. j av a2  s. c  om*/
 * @param table
 * @param indexName
 * @return true if the given index exists on the given table, false otherwise.
 */
public boolean indexExists(String table, String indexName) {
    String sqlStmt = "SHOW INDEX FROM " + table;

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = false;

    try {
        while (resultSet.next()) {
            String keyName = resultSet.getString("key_name").toLowerCase();

            if (keyName.equals(indexName)) {
                returnResult = true;
            }
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return returnResult;
}

From source file:com.runwaysdk.dataaccess.database.general.SQLServer.java

/**
 * Returns true if the given index exists on the given table, false otherwise.
 *
 * @param table/*from w  w  w  . jav  a2 s  . co  m*/
 * @param indexName
 * @return true if the given index exists on the given table, false otherwise.
 */
public boolean indexExists(String table, String indexName) {
    String sqlStmt = "sp_helpindex " + table;

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = false;

    try {
        while (resultSet.next()) {
            String keyName = resultSet.getString("index_name").toLowerCase();

            if (keyName.equals(indexName)) {
                returnResult = true;
            }
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return returnResult;
}

From source file:com.runwaysdk.dataaccess.database.general.MySQL.java

/**
 * Returns a list of string names of the attributes that participate in a
 * group index for the given table with the index of the given name.
 * //ww w .jav  a  2  s. co m
 * @param table
 * @param indexName
 */
public List<String> getGroupIndexAttributes(String table, String indexName) {
    List<String> attributeNames = new LinkedList<String>();

    if (table.trim().equals("") || table == null)
        return attributeNames;

    String sqlStmt = "SHOW INDEX FROM " + table;

    ResultSet resultSet = query(sqlStmt);

    try {
        while (resultSet.next()) {
            String attrName = resultSet.getString("column_name").toLowerCase();
            String keyName = resultSet.getString("key_name").toLowerCase();

            if (keyName.equals(indexName)) {
                attributeNames.add(attrName);
            }
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }
    return attributeNames;
}

From source file:com.runwaysdk.dataaccess.database.general.MySQL.java

/**
 * Returns true if a group attribute index exists with the given name on the
 * given table./*w w  w  .  ja  v a  2  s. c om*/
 * 
 * @param tableName
 * @param indexName
 */
public boolean groupAttributeIndexExists(String table, String indexName) {
    String sqlStmt = "SHOW INDEX FROM " + table;

    ResultSet resultSet = query(sqlStmt);

    boolean indexExists = false;

    try {
        while (resultSet.next()) {
            // Commented out because it is never used: Is this an error?
            String keyName = resultSet.getString("key_name").toLowerCase();

            if (keyName.equals(indexName)) {
                indexExists = true;
                break;
            }
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }

    return indexExists;
}

From source file:com.runwaysdk.dataaccess.database.general.Oracle.java

/**
 * Returns true if a column with the given name exists on the table with the given name, false otherwise.
 *
 * @param columnName assumes column name is lower case.
 * @param tableName/*from   w w w .  j av  a  2s . co m*/
 *
 * @return true if a column with the given name exists on the table with the given name, false otherwise.
 */
@Override
public boolean columnExists(String columnName, String tableName) {
    String queryString = " SELECT column_name \n" + "  FROM user_tab_columns \n" + " WHERE table_name = '"
            + tableName.toUpperCase() + "' \n" + " WHERE column_name = '" + columnName.toUpperCase() + "'";

    ResultSet resultSet = query(queryString);

    try {
        while (resultSet.next()) {
            return true;
        }
    } catch (SQLException sqlEx1) {
        Database.throwDatabaseException(sqlEx1);
    } finally {
        try {
            java.sql.Statement statement = resultSet.getStatement();
            resultSet.close();
            statement.close();
        } catch (SQLException sqlEx2) {
            Database.throwDatabaseException(sqlEx2);
        }
    }
    return false;
}