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.PostgreSQL.java

/**
 * Returns true if a group attribute index exists with the given name on the
 * given table./*  w w  w  .  j  av  a2s . com*/
 * 
 * @param tableName
 * @param indexName
 */
public boolean groupAttributeIndexExists(String table, String indexName) {
    String sqlStmt = "SELECT pg_attribute.attname \n" + "  FROM pg_attribute, pg_class \n"
            + " WHERE pg_class.relname = '" + indexName + "' \n"
            + "   AND pg_attribute.attrelid = pg_class.oid";

    ResultSet resultSet = query(sqlStmt);

    boolean returnValue = false;

    try {
        if (resultSet.next()) {
            returnValue = 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 returnValue;
}

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

/**
 * @see com.runwaysdk.dataaccess.AbstractDatabase#tableExists(java.lang.String)
 *//*from   w w w . ja v  a2 s .c om*/
public boolean tableExists(String tableName) {
    String sqlStmt = "SELECT relname FROM pg_class WHERE relname = '" + tableName + "'";

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = false;

    try {
        if (resultSet.next()) {
            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.PostgreSQL.java

/**
 * Returns true if the given index exists on the given table, false otherwise.
 * //  w  ww .jav  a  2  s .c o  m
 * @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 = "SELECT pg_attribute.attname \n" + "  FROM pg_attribute, pg_class \n"
            + " WHERE pg_class.relname = '" + indexName + "' \n"
            + "   AND pg_attribute.attrelid = pg_class.oid";

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = false;

    try {
        if (resultSet.next()) {
            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.PostgreSQL.java

/**
 * Returns true if a column with the given name exists on the table with the
 * given name, false otherwise./*from  w  w  w .  jav a 2  s. c o  m*/
 * 
 * @param columnName
 *          assumes column name is lower case.
 * @param tableName
 * 
 * @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 sqlStmt = "SELECT pg_attribute.attname  \n" + "  FROM pg_attribute, pg_class  \n"
            + " WHERE pg_class.relname = '" + tableName + "' \n"
            + "   AND pg_attribute.attrelid = pg_class.oid \n" + "   AND pg_attribute.attname = '" + columnName
            + "' \n";

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = false;

    try {
        if (resultSet.next()) {
            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.PostgreSQL.java

@Override
@Transaction/* w ww. j a va2s .  co m*/
public List<String> getViewsByPrefix(String prefix) {
    final String viewName = "viewname";
    String sqlStmt = "SELECT " + viewName + " FROM pg_views WHERE viewowner='" + DatabaseProperties.getUser()
            + "' AND " + viewName + " LIKE '" + prefix.toLowerCase() + "%' ORDER BY " + viewName;
    ResultSet resultSet = this.query(sqlStmt);
    List<String> list = new LinkedList<String>();

    try {
        while (resultSet.next()) {
            list.add(resultSet.getString(viewName));
        }
    } 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 list;
}

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

/**
 * Returns the name of the table on which the given index applies. It is up to
 * the client to close the given connection object.
 * /*  w  ww . ja v a  2  s.  c o m*/
 * @param indexName
 * @param conx
 * @return name of the table on which the given index applies.
 */
public String getTableNameForIndex(String indexName, Connection conx) {
    String sqlStmt = "SELECT class1.relname " + "  FROM pg_class class1, pg_index index, pg_class class2 "
            + " WHERE class2.relname = '" + indexName + "' " + "   AND index.indexrelid = class2.oid "
            + "   AND index.indrelid = class1.oid ";

    ResultSet resultSet = this.query(sqlStmt, conx);

    String tableName = "";

    try {
        while (resultSet.next()) {
            tableName = resultSet.getString("relname").toLowerCase();
        }
    } 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 tableName;

}

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

/**
 * @see com.runwaysdk.dataaccess.database.relationship.AbstractDatabase#getParentCountForChild(java.lang.String,
 *      java.lang.String)/*from  ww  w.  jav  a2  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

/**
 * Returns a list of string names of the attributes that participate in a
 * group unique with the given name./*  www.  j a  v a2 s.com*/
 *
 * @param indexName
 * @param conn it is up to the client to manage the connection object.
 * @param attributeNames
 */
public List<String> getGroupIndexAttributesFromIndexName(String table, String indexName, Connection conn) {
    String sqlStmt = "sp_helpindex " + table;

    ResultSet resultSet = this.query(sqlStmt, conn);

    List<String> attributeNames = new LinkedList<String>();

    try {
        while (resultSet.next()) {
            String attrName = resultSet.getString("index_keys").toLowerCase();
            //     String indexType =  ( ((DynaBean)result.get(i)).get("index_description").toString() ).toLowerCase();
            String keyName = resultSet.getString("index_name").toLowerCase();

            //     if (keyName.equals(indexName) && indexType.contains("unique"))
            if (keyName.equals(indexName)) {
                StringTokenizer st = new StringTokenizer(attrName, ",", false);

                while (st.hasMoreElements()) {
                    attributeNames.add(((String) st.nextElement()).trim());
                }
            }
        }
    } 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.Oracle.java

/**
 * Returns true if a group attribute index exists with the given name and the given attributes on the given table.
 * @param tableName/*from  w ww . j  a v  a 2 s . c o  m*/
 * @param indexName
 * @param attributeColumnNames
 */
public boolean groupAttributeIndexExists(String table, String indexName, List<String> attributeColumnNames) {
    String sqlStmt = " SELECT column_name \n" + "  FROM user_ind_columns \n" + " WHERE index_name = '"
            + indexName.toUpperCase() + "' \n";

    ResultSet resultSet = query(sqlStmt);

    boolean returnResult = true;

    try {
        int resultCount = 0;
        while (resultSet.next()) {
            resultCount++;

            String attrName = resultSet.getString("column_name").toLowerCase();
            if (!attributeColumnNames.contains(attrName)) {
                returnResult = false;
            }

        }

        if (resultCount != attributeColumnNames.size()) {
            returnResult = false;
        }

    } 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.PostgreSQL.java

/**
 * Returns a list of string names of the attributes that participate in a
 * group unique with the given name./*from   w  w  w.  j a va  2s  .  c  om*/
 * 
 * @param indexName
 * @param conn
 *          it is up to the client to manage the connection object.
 * @param attributeNames
 */
public List<String> getGroupIndexAttributesFromIndexName(String indexName, Connection conn) {
    String sqlStmt = "SELECT pg_attribute.attname \n" + "  FROM pg_attribute, pg_class \n"
            + " WHERE pg_class.relname = '" + indexName + "' \n"
            + "   AND pg_attribute.attrelid = pg_class.oid";

    ResultSet resultSet = this.query(sqlStmt, conn);

    List<String> attributeNames = new LinkedList<String>();

    try {
        while (resultSet.next()) {
            String attrName = resultSet.getString("attname").toLowerCase();
            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;
}