Example usage for java.sql ResultSet isLast

List of usage examples for java.sql ResultSet isLast

Introduction

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

Prototype

boolean isLast() throws SQLException;

Source Link

Document

Retrieves whether the cursor is on the last row of this ResultSet object.

Usage

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

@Override
public String getUsertype() {

    StringBuffer sb = null;/*from   www. j  a  va2  s. co m*/
    try {
        sb = new StringBuffer("{'usertype':{");
        sb.append("'name':'all',");
        sb.append("'alltype':[");

        String sql3 = "SELECT * FROM user_type WHERE user_type_id>3";
        PreparedStatement ps3 = DBFactory.getConnection().prepareStatement(sql3);
        ResultSet rs3 = ps3.executeQuery();
        while (rs3.next()) {
            if (rs3.isLast()) {
                sb.append("{'value':'" + rs3.getString(1) + "','type':'" + rs3.getString(2) + "'}");
            } else {
                sb.append("{'value':'" + rs3.getString(1) + "','type':'" + rs3.getString(2) + "'},");
            }

        }
        sb.append("]");
        sb.append("}");
        sb.append("}");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

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

@Override
public String listSubAdmins() {
    StringBuffer sb = null;//from w w  w  . jav a 2s .  com
    sb = new StringBuffer("{'subadmin':{");
    sb.append("'name':'SubAdmin',");
    sb.append("'details':[");

    try {
        String sql = "SELECT * FROM user WHERE user_type_user_type_id!=2 AND user_type_user_type_id!=3 AND user_type_user_type_id!=1";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {

            System.gc();
            if (rs.isLast()) {
                sb.append("{'id':'" + rs.getInt(1) + "','un':'" + rs.getString(2) + "','em':'" + rs.getString(5)
                        + "','state':'" + rs.getInt(19) + "','type':'" + rs.getInt(21) + "'}");
            } else {
                sb.append("{'id':'" + rs.getInt(1) + "','un':'" + rs.getString(2) + "','em':'" + rs.getString(5)
                        + "','state':'" + rs.getInt(19) + "','type':'" + rs.getInt(21) + "'},");
            }

        }
        sb.append("],");
        sb.append("'states':[");

        String sql2 = "SELECT * FROM state";
        PreparedStatement ps2 = DBFactory.getConnection().prepareStatement(sql2);
        ResultSet rs2 = ps2.executeQuery();
        while (rs2.next()) {
            if (rs2.isLast()) {
                sb.append("{'value':'" + rs2.getString(1) + "','state':'" + rs2.getString(2) + "'}");
            } else {
                sb.append("{'value':'" + rs2.getString(1) + "','state':'" + rs2.getString(2) + "'},");
            }

        }

        sb.append("],");
        sb.append("'types':[");
        String sql3 = "SELECT * FROM user_type WHERE user_type_id>3";
        PreparedStatement ps3 = DBFactory.getConnection().prepareStatement(sql3);
        ResultSet rs3 = ps3.executeQuery();
        while (rs3.next()) {
            if (rs3.isLast()) {
                sb.append("{'value':'" + rs3.getString(1) + "','type':'" + rs3.getString(2) + "'}");
            } else {
                sb.append("{'value':'" + rs3.getString(1) + "','type':'" + rs3.getString(2) + "'},");
            }

        }
        sb.append("]");
        sb.append("}");
        sb.append("}");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:org.surfnet.cruncher.repository.StatisticsRepositoryImpl.java

/**
 * {@inheritDoc}/*from w ww .  j a  v a  2 s .  c o m*/
 */
@Override
public List<LoginData> getLogins(final LocalDate start, final LocalDate end, final String idpEntityId,
        final String spEntityId) {
    final List<LoginData> result = new ArrayList<LoginData>();

    NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(cruncherJdbcTemplate);

    String query = "select * from aggregated_log_logins " + "where " + "entryday >= :startDate AND "
            + "entryday <= :endDate AND " + "(:spEntityId IS NULL OR spentityid = :spEntityId) AND "
            + "(:idpEntityId IS NULL OR idpentityid = :idpEntityId) "
            + "order by idpentityid, spentityid, entryday ";

    Map<String, Object> parameterMap = getParameterMap(start, end, idpEntityId, spEntityId);

    namedJdbcTemplate.query(query, parameterMap, new RowMapper<Object>() {
        private Map<LocalDate, Integer> queryResult = new HashMap<LocalDate, Integer>();
        private LoginData currentAggregate = null;

        @Override
        public Object mapRow(ResultSet rs, int row) throws SQLException {
            LoginData currentRow = getLoginDataFromRow(rs);

            /*
             * aggregate if sp/idp entityid differs from previous record
             * do not aggregate if on first record
             * if on last record, aggregate last entries
             */
            if (!currentRow.equals(currentAggregate) && !rs.isFirst()) {
                //record is different, aggregate previous one and start fresh
                result.add(aggregateCurrentEntry(currentAggregate, start, end));
                queryResult = new HashMap<LocalDate, Integer>();

            }
            queryResult.put(new LocalDate(rs.getDate("entryday")), rs.getInt("entrycount"));
            currentAggregate = currentRow;

            if (rs.isLast()) {
                // aggregate last set
                result.add(aggregateCurrentEntry(currentAggregate, start, end));
            }

            /*
             * This is kinda weird, but single row results are stored in 
             * queryResult (hashmap) or aggregated in result (List<loginData)
             */
            return null;
        }

        private LoginData aggregateCurrentEntry(final LoginData loginData, final LocalDate start,
                final LocalDate end) {
            LocalDate current = start;

            int total = 0;
            while (current.isBefore(end.plusDays(1))) {
                Integer count = queryResult.get(current);
                if (count == null) {
                    loginData.getData().add(0);
                } else {
                    loginData.getData().add(count);
                    total += count;
                }
                current = current.plusDays(1);
            }
            loginData.setTotal(total);
            loginData.setPointStart(start.toDate().getTime());
            loginData.setPointEnd(end.toDate().getTime());
            loginData.setPointInterval(POINT_INTERVAL);
            return loginData;
        }

        private LoginData getLoginDataFromRow(ResultSet rs) throws SQLException {
            LoginData result = new LoginData();
            result.setIdpEntityId(rs.getString("idpentityid"));
            result.setIdpname(rs.getString("idpentityname"));
            result.setSpEntityId(rs.getString("spentityid"));
            result.setSpName(rs.getString("spentityname"));
            return result;
        }
    });
    return result;
}

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

@Override
public String getUserRate() {

    StringBuffer sb = null;//ww w. jav  a2s .c  o  m
    sb = new StringBuffer("{'userreg':{");
    sb.append("'name':'User Rate',");
    sb.append("'rate':[");
    try {
        String sql = "select count(user_id),DATE(date) from user group by DATE(date)";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        int max = 0;
        while (rs.next()) {
            max++;
            System.out.println("U1: " + rs.getDouble(1));
            System.out.println("U2: " + rs.getString(2));

            if (rs.isLast()) {
                sb.append("{'date':'" + rs.getString(2) + "','value':'" + rs.getDouble(1) + "'}");
            } else {
                sb.append("{'date':'" + rs.getString(2) + "','value':'" + rs.getDouble(1) + "'},");
            }

        }
        sb.append("],");
        if (max % 2 == 0) {
            sb.append("'max':'" + max + "'");
        } else {
            sb.append("'max':'" + max++ + "'");
        }
        sb.append("}");
        sb.append("}");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:com.flexoodb.engines.FlexJAXBMappedDBDataEngine.java

public Collection<Object> runQuery(String query, Class c, boolean usedefaultimplementation) throws Exception {
    Vector v = new Vector();
    Connection conn = null;/*from   w  w w.ja  va2 s.c o  m*/
    try {
        checkForSQLInjection(query);

        conn = (Connection) _pool.getConnection();

        String tablename = query.split("\\s")[3];
        String oldtablename = query.split("\\s")[3];

        tablename = (tablename.endsWith("type") ? tablename.substring(0, tablename.lastIndexOf("type"))
                : tablename).toLowerCase();

        String idcolumn = null;
        String realtablename = null;
        String parentidcolumn = null;
        boolean includeidcolumns = false;
        String proxtablename = null;

        PreparedStatement ps = null;

        FlexElement element = _elements.get(tablename);
        if (element == null) {
            // if we cant find the table in the query then we look for the tablename using the passed class
            proxtablename = c.getSimpleName().toLowerCase();
            proxtablename = (proxtablename.endsWith("type")
                    ? proxtablename.substring(0, proxtablename.lastIndexOf("type"))
                    : proxtablename).toLowerCase();
            element = _elements.get(proxtablename);

            if (element == null) {
                throw new Exception("could not process query, due to: no record artifact table found.");
            }

        } else {
            realtablename = element.getAttribute("realtablename").getValue();
        }

        idcolumn = element.getAttribute("idcolumn").getValue();
        parentidcolumn = element.getAttribute("parentidcolumn").getValue();
        includeidcolumns = element.getAttribute("includeidcolumns").getValue() == null ? false
                : (element.getAttribute("includeidcolumns").getValue().equalsIgnoreCase("true"));

        if (usedefaultimplementation) {
            StringBuffer q = new StringBuffer();

            if (query.toUpperCase().indexOf("WHERE") > 0) {
                q.append(query.substring(query.toUpperCase().indexOf("WHERE"), query.length()));
            } else {
                q.append(query.substring(query.toUpperCase().indexOf(oldtablename.toUpperCase()),
                        query.length()));
                //q.append(query.substring(query.toUpperCase().indexOf(oldtablename.toUpperCase())+oldtablename.length()+1,query.length()));
                if (q.toString().equalsIgnoreCase(oldtablename)) {
                    q = new StringBuffer();
                }
            }

            if (query.toUpperCase().indexOf("LIMIT") > 0) {
                //q.append(query.substring(query.toUpperCase().indexOf("LIMIT"),query.length()));
            }

            // we replace parentid column with the one in the table.
            if (parentidcolumn != null) {
                q = new StringBuffer(
                        FlexUtils.replaceFirstString(q.toString(), " parentid", " " + parentidcolumn));
            }

            String qry = q.toString().trim();
            qry = qry.substring(qry.indexOf(" ") > 0 ? qry.indexOf(" ") : 0).trim();

            //System.out.println("parentid:"+parentidcolumn+" orig query:"+qry+" query:select * from "+((realtablename!=null)?realtablename:tablename.toLowerCase())+" "+(qry!=null && !qry.startsWith("order")? (!qry.isEmpty()?"where ":""):"")+qry);
            ps = (PreparedStatement) conn.prepareStatement(
                    "select * from " + ((realtablename != null) ? realtablename : tablename.toLowerCase()) + " "
                            + (qry != null && !qry.startsWith("order")
                                    ? ((!qry.isEmpty() && !qry.startsWith("limit")) ? "where " : "")
                                    : "")
                            + qry);

        } else {
            //System.out.println(">>>>"+query);
            ps = (PreparedStatement) conn.prepareStatement(query);
        }

        ResultSet rec = ps.executeQuery();
        RecordSet res = new RecordSet(rec);

        while (res != null && res.size() > 0 && res.next()) {
            String id = res.getString(idcolumn);

            //String xml = FlexUtils.getRDBMSRecordAsXML(tablename, res, idcolumn, parentidcolumn,includeidcolumns);
            String xml = FlexUtils.getRDBMSRecordAsXML((proxtablename != null ? proxtablename : tablename), res,
                    idcolumn, parentidcolumn, includeidcolumns, element);

            String i = idcolumn != null ? res.getString(idcolumn) : res.getString("id");
            String p = parentidcolumn != null ? res.getString(parentidcolumn) : res.getString("parentid");
            Object o2 = new FlexContainer(_flexutils.getObject(xml, c));
            ((FlexContainer) o2).setId(id);
            ((FlexContainer) o2).setParentId(p);

            //Object o2 = _flexutils.getObject(xml,c);
            if (o2 != null) {
                v.add(o2);
            }

            if (rec.isLast()) {
                break;
            }
        }
    } catch (Exception f) {
        System.out.println(">>>>QUERY FAULT:[" + query + "]");
        f.printStackTrace();
        throw f;
    } finally {
        try {
            if (conn != null) {
                _pool.releaseConnection(conn);
            }

        } catch (Exception g) {
        }
    }
    return v;
}

From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java

/**
 * Produce a JDOM Element for an instance of Results object.
 * <br>/*  w w  w . ja  va2  s.co m*/
 * @param object for which the JDOM Element is to be produced.
 * @param beginRow The starting row from which the results are to be converted to XML.
 * @param endRow The row until which the results are to be converted to XML.
 * @return the JDOM element of the results object that was converted to XML.
 * @exception JDOMException if there is an error producing XML.
 * @exception SQLException if there is an error walking through the ResultSet object.
 */
private Element produceResults(ResultSet object, int beginRow, int endRow) throws JDOMException, SQLException {

    if (object.isClosed()) {
        throw new SQLException("ResultSet is closed at this point, unable to product results"); //$NON-NLS-1$

    }

    if (beginRow < START_ROW) {
        throw new IllegalArgumentException("The starting row cannot be less than 1."); //$NON-NLS-1$
    } else if (beginRow > endRow) {
        throw new IllegalArgumentException("The starting row cannot be less than the ending row."); //$NON-NLS-1$
    }

    int currentRow = object.getRow() + 1;

    if (beginRow > currentRow) {
        while (!object.isLast() && currentRow != beginRow) {
            object.next();
            currentRow++;
        }

    } else if (beginRow < currentRow) {
        while (!object.isFirst() && currentRow != beginRow) {
            object.previous();
            currentRow--;
        }
    }

    return produceMsg(object, endRow);
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@SuppressWarnings("deprecation")
@Test//ww  w  .  j a v  a 2 s.  co m
public void testResultSetWhenClosed() throws Exception {
    Statement statement = getConnection().createStatement();
    ResultSet rs = statement.executeQuery(SQL_EMPS);

    rs.close();

    try {
        rs.isBeforeFirst();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.isAfterLast();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.isFirst();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.isLast();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.beforeFirst();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.afterLast();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.first();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.last();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.next();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getRow();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getType();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getConcurrency();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.rowUpdated();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.rowDeleted();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.rowInserted();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getStatement();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.wasNull();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getString(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getString("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBoolean("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getByte("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getShort("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getInt("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getLong("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFloat("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDouble("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBigDecimal("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBytes("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate(1, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getDate("col1", null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime(1, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTime("col1", null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp(1, null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getTimestamp("col1", null);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getAsciiStream("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getUnicodeStream("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getBinaryStream("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getCharacterStream("col1");
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getMetaData();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.setFetchDirection(1);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFetchDirection();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.setFetchSize(100);
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getFetchSize();
        fail();
    } catch (SQLException ignore) {
    }

    try {
        rs.getHoldability();
        fail();
    } catch (SQLException ignore) {
    }

    statement.close();
}

From source file:org.wso2.carbon.appmgt.usage.client.impl.AppUsageStatisticsRdbmsClient.java

public List<AppHitsStatsDTO> getAppHitsOverTime(String fromDate, String toDate, int tenantId)
        throws AppUsageQueryServiceClientException {

    if (dataSource == null) {
        throw new AppUsageQueryServiceClientException(errorMsg);
    }/*ww  w.  j  a  va  2 s  .  c o m*/

    Map<String, AppHitsStatsDTO> appHitsStatsMap = new HashMap<String, AppHitsStatsDTO>();
    Connection connection = null;
    PreparedStatement getAppHitsStatement = null;
    ResultSet appInfoResult = null;
    List<AppHitsStatsDTO> appHitsStatsList = null;
    try {
        connection = dataSource.getConnection();
        String queryToGetAppsHits = "SELECT APP_NAME, CONTEXT, COUNT(*) "
                + "AS TOTAL_HITS_COUNT, VERSION FROM APM_APP_HITS WHERE TENANT_ID = ? AND HIT_TIME "
                + "BETWEEN ? AND ? GROUP BY APP_NAME, CONTEXT,VERSION ORDER BY TOTAL_HITS_COUNT";
        getAppHitsStatement = connection.prepareStatement(queryToGetAppsHits);
        getAppHitsStatement.setInt(1, tenantId);
        getAppHitsStatement.setString(2, fromDate);
        getAppHitsStatement.setString(3, toDate);
        appInfoResult = getAppHitsStatement.executeQuery();

        boolean noData = true;
        String queryToGetUserHits = "SELECT APP_NAME, CONTEXT, USER_ID, COUNT(*) AS USER_HITS_COUNT, VERSION "
                + "FROM APM_APP_HITS WHERE CONTEXT IN ( ";

        while (appInfoResult.next()) {
            noData = false;
            AppHitsStatsDTO appHitsStats = new AppHitsStatsDTO();
            String context = appInfoResult.getString(APIUsageStatisticsClientConstants.CONTEXT);
            appHitsStats.setContext(context);
            queryToGetUserHits += "'" + context + "'";
            if (!appInfoResult.isLast()) {
                queryToGetUserHits += ",";
            }
            String appNameWithVersion = appInfoResult.getString("APP_NAME") + "(v"
                    + appInfoResult.getString("VERSION") + ")";
            appHitsStats.setAppName(appNameWithVersion);
            appHitsStats
                    .setTotalHitCount(appInfoResult.getInt(APIUsageStatisticsClientConstants.TOTAL_HITS_COUNT));
            appHitsStatsMap.put(appHitsStats.getAppName(), appHitsStats);
        }
        queryToGetUserHits += ") GROUP BY APP_NAME, CONTEXT, USER_ID, VERSION ORDER BY USER_ID";
        if (!noData) {
            appHitsStatsList = getUserHitsStats(connection, appHitsStatsMap, queryToGetUserHits);
        }
    } catch (SQLException e) {
        throw new AppUsageQueryServiceClientException(
                "SQL Exception is occurred when " + "reading apps hits from SQL table" + e.getMessage(), e);
    } finally {
        APIMgtDBUtil.closeAllConnections(getAppHitsStatement, connection, appInfoResult);
    }
    return appHitsStatsList;
}

From source file:org.wso2.carbon.ml.database.internal.MLDatabaseService.java

/**
 * Get feature names in order and separated by the given column separator.
 *//*  w  w w . j  a  va 2 s .  c  o m*/
@Override
public String getFeatureNamesInOrder(long datasetId, String columnSeparator) throws DatabaseHandlerException {

    Connection connection = null;
    PreparedStatement getFeatureNamesStatement = null;
    ResultSet result = null;
    StringBuilder headerRow = new StringBuilder();

    try {
        connection = dbh.getDataSource().getConnection();

        // Create a prepared statement and retrieve model configurations
        getFeatureNamesStatement = connection.prepareStatement(SQLQueries.GET_FEATURE_NAMES_IN_ORDER);
        getFeatureNamesStatement.setLong(1, datasetId);

        result = getFeatureNamesStatement.executeQuery();
        // Convert the result in to a string array to e returned.
        while (result.next()) {
            headerRow.append(result.getString(1));
            if (!result.isLast()) {
                headerRow.append(columnSeparator);
            }
        }
        return headerRow.toString();
    } catch (SQLException e) {
        throw new DatabaseHandlerException("An error occurred while retrieving feature "
                + "names of the dataset : " + datasetId + ": " + e.getMessage(), e);
    } finally {
        // Close the database resources.
        MLDatabaseUtils.closeDatabaseResources(connection, getFeatureNamesStatement, result);
    }
}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@Test
public void testUnsupportedOperations() throws Exception {
    Statement statement = getConnection().createStatement();
    ResultSet rs = statement.executeQuery(SQL_EMPS);

    try {//  w  w w  .j  a va 2 s.c om
        rs.getWarnings();
        fail();
    } catch (UnsupportedOperationException ignore) {
    }

    try {
        rs.clearWarnings();
        fail();
    } catch (UnsupportedOperationException ignore) {
    }

    try {
        rs.getCursorName();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("ename");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.isLast();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.beforeFirst();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.afterLast();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.first();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.last();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.absolute(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.relative(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.previous();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.moveToCurrentRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNull(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNull("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBoolean(1, true);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBoolean("col1", true);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateByte(1, (byte) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateByte("col1", (byte) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateShort(1, (short) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateShort("col1", (short) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateInt(1, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateInt("col1", 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateLong(1, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateLong("col1", (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateFloat(1, (float) 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateFloat("col1", (float) 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDouble(1, 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDouble("col1", 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBigDecimal(1, new BigDecimal("100000000"));
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBigDecimal("col1", new BigDecimal("100000000"));
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateString(1, "Unknown");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateString("col1", "Unknown");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBytes(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBytes("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDate(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDate("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTime(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTime("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTimestamp(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTimestamp("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject(1, null, 1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject("col1", null, 1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.insertRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.deleteRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.refreshRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.cancelRowUpdates();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.moveToInsertRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1, (Map<String, Class<?>>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("col1", (Map<String, Class<?>>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRef(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRef("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getBlob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getBlob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getClob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getClob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getURL(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getURL("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRef(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRef("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, (Blob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", (Blob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, (Clob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", (Clob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateArray(1, (Array) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateArray("col1", (Array) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRowId(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRowId("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRowId(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRowId("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNString(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNString("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, (NClob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", (NClob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNClob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNClob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getSQLXML(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getSQLXML("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateSQLXML(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateSQLXML("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNString(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNString("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNCharacterStream(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNCharacterStream("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, (InputStream) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", (InputStream) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1, (Class<?>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("col1", (Class<?>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    rs.close();
    assertTrue(rs.isClosed());

    statement.close();
    assertTrue(statement.isClosed());
}