Example usage for java.sql ResultSet first

List of usage examples for java.sql ResultSet first

Introduction

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

Prototype

boolean first() throws SQLException;

Source Link

Document

Moves the cursor to the first row in this ResultSet object.

Usage

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

@Override
public MLAnalysis getAnalysisOfProject(int tenantId, String userName, long projectId, String analysisName)
        throws DatabaseHandlerException {
    Connection connection = null;
    ResultSet result = null;
    PreparedStatement statement = null;
    try {/*from   w ww.j  a  va 2  s. co m*/
        connection = dbh.getDataSource().getConnection();
        statement = connection.prepareStatement(SQLQueries.GET_ANALYSIS_OF_PROJECT);
        statement.setInt(1, tenantId);
        statement.setString(2, userName);
        statement.setLong(3, projectId);
        statement.setString(4, analysisName);
        result = statement.executeQuery();
        if (result.first()) {
            MLAnalysis analysis = new MLAnalysis();
            analysis.setId(result.getLong(1));
            analysis.setProjectId(result.getLong(2));
            analysis.setComments(MLDatabaseUtils.toString(result.getClob(3)));
            analysis.setName(result.getString(4));
            analysis.setTenantId(tenantId);
            analysis.setUserName(userName);
            return analysis;
        } else {
            return null;
        }
    } catch (SQLException e) {
        throw new DatabaseHandlerException(" An error has occurred while extracting analysis for project id: "
                + projectId + " and analysis name: " + analysisName, e);
    } finally {
        // Close the database resources.
        MLDatabaseUtils.closeDatabaseResources(connection, statement, result);
    }
}

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

/**
 * Retrieve the SamplePoints object for a given value-set.
 *
 * @param tenantId Tenant id/*from   www  . j a v  a  2  s.c  om*/
 * @param user Tenant user name
 * @param versionsetId Unique Identifier of the dataset version
 * @return SamplePoints object of the value-set
 * @throws DatabaseHandlerException
 */
public SamplePoints getVersionsetSample(int tenantId, String user, long versionsetId)
        throws DatabaseHandlerException {

    Connection connection = null;
    PreparedStatement updateStatement = null;
    ResultSet result = null;
    SamplePoints samplePoints = null;
    try {
        connection = dbh.getDataSource().getConnection();
        connection.setAutoCommit(true);
        updateStatement = connection.prepareStatement(SQLQueries.GET_SAMPLE_POINTS);
        updateStatement.setLong(1, versionsetId);
        updateStatement.setInt(2, tenantId);
        updateStatement.setString(3, user);
        result = updateStatement.executeQuery();
        if (result.first() && result.getBinaryStream(1) != null) {
            samplePoints = MLDBUtil.getSamplePointsFromInputStream(result.getBinaryStream(1));
        }
        return samplePoints;
    } catch (Exception e) {
        // Roll-back the changes.
        MLDatabaseUtils.rollBack(connection);
        throw new DatabaseHandlerException("An error occurred while retrieving the sample of "
                + " dataset version " + versionsetId + ": " + e.getMessage(), e);
    } finally {
        // Close the database resources.
        MLDatabaseUtils.closeDatabaseResources(connection, updateStatement, result);
    }
}

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

/**
 * Retrieve and returns the Summary statistics for a given feature of a given data-set version, from the database.
 *
 * @param tenantId Tenant id/*w  ww  . j a  v  a2s.co m*/
 * @param user Tenant user name
 * @param analysisId Unique identifier of the analysis
 * @param featureName Name of the feature of which summary statistics are needed
 * @return JSON string containing the summary statistics
 * @throws DatabaseHandlerException
 */
@Override
public String getSummaryStats(int tenantId, String user, long analysisId, String featureName)
        throws DatabaseHandlerException {

    Connection connection = null;
    PreparedStatement getSummaryStatement = null;
    ResultSet result = null;
    try {
        connection = dbh.getDataSource().getConnection();
        connection.setAutoCommit(true);
        getSummaryStatement = connection.prepareStatement(SQLQueries.GET_SUMMARY_STATS);
        getSummaryStatement.setLong(1, analysisId);
        getSummaryStatement.setString(2, featureName);
        getSummaryStatement.setInt(3, tenantId);
        getSummaryStatement.setString(4, user);
        result = getSummaryStatement.executeQuery();
        if (result.first()) {
            return result.getString(1);
        } else {
            return "";
        }
    } catch (SQLException e) {
        throw new DatabaseHandlerException(
                "An error occurred while retrieving summary " + "statistics for the feature \"" + featureName
                        + "\" of the analysis " + analysisId + ": " + e.getMessage(),
                e);
    } finally {
        // Close the database resources
        MLDatabaseUtils.closeDatabaseResources(connection, getSummaryStatement, result);
    }
}

From source file:uk.ac.ed.epcc.webapp.model.data.Repository.java

/** Set the table References for the fields  
 * /*from  w w w  .  j  a  v  a 2 s  .c  om*/
 * @param ctx
 * @param c
 * @throws SQLException 
 */
private void setReferences(AppContext ctx, Connection c) throws SQLException {
    //Logger log = ctx.getService(LoggerService.class).getLogger(getClass());
    //log.debug("SetReferences for "+getTable());
    // look for foreign keys to identify remote tables.
    DatabaseMetaData meta = c.getMetaData();
    ResultSet rs = meta.getImportedKeys(c.getCatalog(), null, table_name);
    if (rs.first()) {
        //log.debug("Have foreign key");
        do {
            String field = rs.getString("FKCOLUMN_NAME");
            String table = rs.getString("PKTABLE_NAME");
            String key_name = rs.getString("FK_NAME");
            short seq = rs.getShort("KEY_SEQ");
            if (seq == 1) {
                FieldInfo info = fields.get(field);
                if (info.isNumeric()) {
                    String name = REFERENCE_PREFIX + param_name + "." + info.getName(false);
                    table = ctx.getInitParameter(name, table); // use param in preference because of windows case mangle
                    String tag = TableToTag(ctx, table);
                    //log.debug("field "+field+" references "+table);
                    info.setReference(true, key_name, tag);
                }
            }
        } while (rs.next());
    }
    // now try explicit references set from properties
    for (FieldInfo i : fields.values()) {
        if (i.getReferencedTable() == null) {
            //use param name for table rename
            String tag = REFERENCE_PREFIX + param_name + "." + i.getName(false);
            String table = ctx.getInitParameter(tag);
            //log.debug("tag "+tag+" resolves to "+table);
            i.setReference(false, null, table);
        }
    }
}

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

@Override
public void insertModelConfigurations(long analysisId, List<MLModelConfiguration> modelConfigs)
        throws DatabaseHandlerException {

    Connection connection = null;
    PreparedStatement insertStatement = null;
    PreparedStatement searchStatement = null;
    ResultSet result;
    try {//from w ww .java  2  s .co m
        // Insert the model configuration to the database.
        connection = dbh.getDataSource().getConnection();
        connection.setAutoCommit(false);

        for (MLModelConfiguration mlModelConfiguration : modelConfigs) {
            String key = mlModelConfiguration.getKey();
            String value = mlModelConfiguration.getValue();
            searchStatement = connection.prepareStatement(SQLQueries.GET_A_MODEL_CONFIGURATION);
            searchStatement.setLong(1, analysisId);
            searchStatement.setString(2, key);
            result = searchStatement.executeQuery();
            if (result.first()) {
                insertStatement = connection.prepareStatement(SQLQueries.UPDATE_MODEL_CONFIGURATION);
                insertStatement.setString(1, value);
                insertStatement.setLong(2, analysisId);
                insertStatement.setString(3, key);
            } else {
                insertStatement = connection.prepareStatement(SQLQueries.INSERT_MODEL_CONFIGURATION);
                insertStatement.setLong(1, analysisId);
                insertStatement.setString(2, key);
                insertStatement.setString(3, value);
            }
            insertStatement.execute();
        }
        connection.commit();
        if (logger.isDebugEnabled()) {
            logger.debug("Successfully inserted the model configuration");
        }
    } catch (SQLException e) {
        // Roll-back the changes.
        MLDatabaseUtils.rollBack(connection);
        throw new DatabaseHandlerException("An error occurred while inserting model configuration "
                + " to the database: " + e.getMessage(), e);
    } finally {
        // Enable auto commit.
        MLDatabaseUtils.enableAutoCommit(connection);
        // Close the database resources.
        MLDatabaseUtils.closeDatabaseResources(connection, searchStatement);
        MLDatabaseUtils.closeDatabaseResources(connection, insertStatement);
    }
}

From source file:com.krawler.esp.servlets.AdminServlet.java

public static String getCompanySubscriptionDetails(Connection conn, HttpServletRequest request,
        String companyid) throws ServiceException {
    PreparedStatement pstmt = null;
    String res = null;/*from  w w w .  j  a  va 2s.c  o  m*/
    try {
        KWLJsonConverter KWL = new KWLJsonConverter();
        JSONObject resObj = new JSONObject();
        boolean flg = false;
        pstmt = conn.prepareStatement("SELECT featurelist.featureid, featurename, subscriptiondate, expdate "
                + "FROM companysubscription INNER JOIN featurelist ON companysubscription.featureid=featurelist.featureid "
                + "WHERE companyid = ?");
        pstmt.setString(1, companyid);
        ResultSet rs = pstmt.executeQuery();
        pstmt = conn.prepareStatement("SELECT * FROM featurelist");
        ResultSet rs1 = pstmt.executeQuery();
        while (rs1.next()) {
            JSONObject temp = new JSONObject();
            int fid = rs1.getInt("featureid");
            while (rs.next()) {
                if (fid == rs.getInt("featureid")) {
                    temp.put("featureid", fid);
                    temp.put("subscriptiondate", rs.getDate("subscriptiondate"));
                    temp.put("featurename", rs.getString("featurename"));
                    temp.put("expdate", rs.getDate("expdate"));
                    temp.put("subscribed", true);
                    flg = true;
                    break;
                }
            }
            if (!flg) {
                temp.put("featureid", fid);
                //                    temp.put("subscriptiondate", rs.getDate("subscriptiondate"));
                temp.put("featurename", rs1.getString("featurename"));
                //                    temp.put("expdate", rs.getDate("expdate"));
                temp.put("subscribed", false);
            }
            rs.first();
            flg = false;
            resObj.append("data", temp);
        }
        res = resObj.toString();
    } catch (SQLException e) {
        res = KWLErrorMsgs.rsSuccessFalse;
        //            System.out.print("dfg");
    } catch (JSONException ex) {
        res = KWLErrorMsgs.rsSuccessFalse;
    }
    return res;
}

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 {//from w  w  w  .ja  v a2  s . c  o  m
        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());
}

From source file:org.ims.ssp.samplerte.server.SSP_Servlet.java

/**
 *
 * Retrieve record from DB.//w ww. j ava2  s.co m
 *
 * @param iLearnerID
 * @param iBucketID
 * @param iCourseID
 * @param iSCOID
 * @param iManagedBucketIndex
 * @param iPersistence
 * @param iReallocateFailure
 *
 * @return - Status or result information about the outcome of this call.
 */
private BucketAllocation retrieveDBRecord(String iLearnerID, String iBucketID, String iCourseID, String iSCOID,
        int iManagedBucketIndex, int iPersistence, boolean iReallocateFailure) {
    BucketAllocation result = new BucketAllocation();
    ResultSet rsSSP_BucketTbl = null;

    try {
        new SSP_DBHandler();
        Connection conn = SSP_DBHandler.getConnection();
        Statement stmtSelectSSP_BucketTbl = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

        String sqlSelectSSP_BucketTbl = "";

        if (iLearnerID != null) {
            sqlSelectSSP_BucketTbl = "LearnerID = '" + iLearnerID + "'";
        }

        if (iBucketID != null) {
            if (sqlSelectSSP_BucketTbl != "") {
                sqlSelectSSP_BucketTbl += " AND ";
            }
            sqlSelectSSP_BucketTbl += "BucketID = '" + iBucketID + "'";
        }

        if (iCourseID != null) {
            if (sqlSelectSSP_BucketTbl != "") {
                sqlSelectSSP_BucketTbl += " AND ";
            }
            sqlSelectSSP_BucketTbl += "CourseID = '" + iCourseID + "'";
        }

        if (iSCOID != null) {
            if (sqlSelectSSP_BucketTbl != "") {
                sqlSelectSSP_BucketTbl += " AND ";
            }
            sqlSelectSSP_BucketTbl += "SCOID = '" + iSCOID + "'";
        }

        if (iManagedBucketIndex >= 0) {
            if (sqlSelectSSP_BucketTbl != "") {
                sqlSelectSSP_BucketTbl += " AND ";
            }
            sqlSelectSSP_BucketTbl += "ManagedBucketIndex = " + iManagedBucketIndex;
        }

        if (sqlSelectSSP_BucketTbl != "") {
            sqlSelectSSP_BucketTbl += " AND ";
        }
        sqlSelectSSP_BucketTbl += "ReallocateFailure = " + iReallocateFailure;

        if (iPersistence != -1) {
            if (StringUtils.isNotEmpty(sqlSelectSSP_BucketTbl)) {
                sqlSelectSSP_BucketTbl += " AND ";
            }
            sqlSelectSSP_BucketTbl += "Persistence = " + iPersistence;
        }

        sqlSelectSSP_BucketTbl = "SELECT * FROM SSP_BucketAllocateTbl WHERE " + sqlSelectSSP_BucketTbl;

        if (_Debug) {
            System.out.println("SQL stmt in retieve record: " + sqlSelectSSP_BucketTbl);
        }

        synchronized (stmtSelectSSP_BucketTbl) {
            rsSSP_BucketTbl = stmtSelectSSP_BucketTbl.executeQuery(sqlSelectSSP_BucketTbl);
        }

        // determine how many records came back
        int bucketCount = 0;
        while (rsSSP_BucketTbl.next()) {
            bucketCount++;
        }

        if (bucketCount == 1) {
            rsSSP_BucketTbl.first();

            result.setAllocationStatus(rsSSP_BucketTbl.getInt("Status"));
            result.setBucketID(iBucketID);
            result.setBucketType(rsSSP_BucketTbl.getString("BucketType"));
            result.setMinimumSizeInt(rsSSP_BucketTbl.getInt("Min"));
            result.setPersistence(rsSSP_BucketTbl.getInt("Persistence"));
            result.setReducibleBoolean(rsSSP_BucketTbl.getBoolean("Reducible"));
            result.setRequestedSizeInt(rsSSP_BucketTbl.getInt("Requested"));
            result.setSCOID(iSCOID);
            result.setActivityID(rsSSP_BucketTbl.getInt("ActivityID"));
        }

        stmtSelectSSP_BucketTbl.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}

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

@Override
public void updateSummaryStatistics(long datasetSchemaId, long datasetVersionId, SummaryStats summaryStats)
        throws DatabaseHandlerException {

    int count = getFeatureCount(datasetSchemaId);

    Connection connection = null;
    PreparedStatement insertFeatureDefaults = null, getFeatureIdStmt = null, insertFeatureSummary = null;
    ResultSet result;
    try {//from ww  w . j  a  v  a2  s .c  o  m
        JSONArray summaryStatJson;
        connection = dbh.getDataSource().getConnection();
        connection.setAutoCommit(false);
        int columnIndex;
        for (Map.Entry<String, Integer> columnNameMapping : summaryStats.getHeaderMap().entrySet()) {
            columnIndex = columnNameMapping.getValue();
            // Get the JSON representation of the column summary.
            summaryStatJson = createJson(summaryStats.getType()[columnIndex],
                    summaryStats.getGraphFrequencies().get(columnIndex), summaryStats.getMissing()[columnIndex],
                    summaryStats.getUnique()[columnIndex], summaryStats.getDescriptiveStats().get(columnIndex));

            if (count == 0) {
                insertFeatureDefaults = connection.prepareStatement(SQLQueries.INSERT_FEATURE_DEFAULTS);
                insertFeatureDefaults.setLong(1, datasetSchemaId);
                insertFeatureDefaults.setString(2, columnNameMapping.getKey());
                insertFeatureDefaults.setString(3, summaryStats.getType()[columnIndex]);
                insertFeatureDefaults.setInt(4, columnIndex);
                insertFeatureDefaults.execute();
            }

            // Get feature id
            getFeatureIdStmt = connection.prepareStatement(SQLQueries.GET_FEATURE_ID);
            getFeatureIdStmt.setLong(1, datasetSchemaId);
            getFeatureIdStmt.setString(2, columnNameMapping.getKey());
            result = getFeatureIdStmt.executeQuery();
            long featureId = -1;
            if (result.first()) {
                featureId = result.getLong(1);
            }

            insertFeatureSummary = connection.prepareStatement(SQLQueries.INSERT_FEATURE_SUMMARY);
            insertFeatureSummary.setLong(1, featureId);
            insertFeatureSummary.setString(2, columnNameMapping.getKey());
            insertFeatureSummary.setLong(3, datasetVersionId);
            insertFeatureSummary.setString(4, summaryStatJson.toString());
            insertFeatureSummary.execute();
        }
        connection.commit();
        if (logger.isDebugEnabled()) {
            logger.debug("Successfully updated the summary statistics for dataset version " + datasetVersionId);
        }
    } catch (Exception e) {
        // Roll-back the changes.
        MLDatabaseUtils.rollBack(connection);
        throw new DatabaseHandlerException("An error occurred while updating the database "
                + "with summary statistics of the dataset " + datasetVersionId + ": " + e.getMessage(), e);
    } finally {
        // Enable auto commit.
        MLDatabaseUtils.enableAutoCommit(connection);
        // Close the database resources.
        MLDatabaseUtils.closeDatabaseResources(connection, insertFeatureDefaults);
        MLDatabaseUtils.closeDatabaseResources(connection, getFeatureIdStmt);
        MLDatabaseUtils.closeDatabaseResources(connection, insertFeatureSummary);
    }
}

From source file:org.pentaho.di.core.database.Database.java

public void first(ResultSet rs) throws KettleDatabaseException {
    try {//  w w  w .j a  v  a 2 s .c o m
        rs.first();
    } catch (SQLException e) {
        throw new KettleDatabaseException("Unable to move resultset to the first position", e);
    }
}