Example usage for java.sql ResultSet getObject

List of usage examples for java.sql ResultSet getObject

Introduction

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

Prototype

Object getObject(String columnLabel) throws SQLException;

Source Link

Document

Gets the value of the designated column in the current row of this ResultSet object as an Object in the Java programming language.

Usage

From source file:ExecuteSQL.java

/**
 * This method attempts to output the contents of a ResultSet in a textual
 * table. It relies on the ResultSetMetaData class, but a fair bit of the
 * code is simple string manipulation.//from  w  w w  . ja v  a2 s.co m
 */
static void printResultsTable(ResultSet rs, OutputStream output) throws SQLException {
    // Set up the output stream
    PrintWriter out = new PrintWriter(output);

    // Get some "meta data" (column names, etc.) about the results
    ResultSetMetaData metadata = rs.getMetaData();

    // Variables to hold important data about the table to be displayed
    int numcols = metadata.getColumnCount(); // how many columns
    String[] labels = new String[numcols]; // the column labels
    int[] colwidths = new int[numcols]; // the width of each
    int[] colpos = new int[numcols]; // start position of each
    int linewidth; // total width of table

    // Figure out how wide the columns are, where each one begins,
    // how wide each row of the table will be, etc.
    linewidth = 1; // for the initial '|'.
    for (int i = 0; i < numcols; i++) { // for each column
        colpos[i] = linewidth; // save its position
        labels[i] = metadata.getColumnLabel(i + 1); // get its label
        // Get the column width. If the db doesn't report one, guess
        // 30 characters. Then check the length of the label, and use
        // it if it is larger than the column width
        int size = metadata.getColumnDisplaySize(i + 1);
        if (size == -1)
            size = 30; // Some drivers return -1...
        if (size > 500)
            size = 30; // Don't allow unreasonable sizes
        int labelsize = labels[i].length();
        if (labelsize > size)
            size = labelsize;
        colwidths[i] = size + 1; // save the column the size
        linewidth += colwidths[i] + 2; // increment total size
    }

    // Create a horizontal divider line we use in the table.
    // Also create a blank line that is the initial value of each
    // line of the table
    StringBuffer divider = new StringBuffer(linewidth);
    StringBuffer blankline = new StringBuffer(linewidth);
    for (int i = 0; i < linewidth; i++) {
        divider.insert(i, '-');
        blankline.insert(i, " ");
    }
    // Put special marks in the divider line at the column positions
    for (int i = 0; i < numcols; i++)
        divider.setCharAt(colpos[i] - 1, '+');
    divider.setCharAt(linewidth - 1, '+');

    // Begin the table output with a divider line
    out.println(divider);

    // The next line of the table contains the column labels.
    // Begin with a blank line, and put the column names and column
    // divider characters "|" into it. overwrite() is defined below.
    StringBuffer line = new StringBuffer(blankline.toString());
    line.setCharAt(0, '|');
    for (int i = 0; i < numcols; i++) {
        int pos = colpos[i] + 1 + (colwidths[i] - labels[i].length()) / 2;
        overwrite(line, pos, labels[i]);
        overwrite(line, colpos[i] + colwidths[i], " |");
    }

    // Then output the line of column labels and another divider
    out.println(line);
    out.println(divider);

    // Now, output the table data. Loop through the ResultSet, using
    // the next() method to get the rows one at a time. Obtain the
    // value of each column with getObject(), and output it, much as
    // we did for the column labels above.
    while (rs.next()) {
        line = new StringBuffer(blankline.toString());
        line.setCharAt(0, '|');
        for (int i = 0; i < numcols; i++) {
            Object value = rs.getObject(i + 1);
            if (value != null)
                overwrite(line, colpos[i] + 1, value.toString().trim());
            overwrite(line, colpos[i] + colwidths[i], " |");
        }
        out.println(line);
    }

    // Finally, end the table with one last divider line.
    out.println(divider);
    out.flush();
}

From source file:gov.nih.nci.cabig.caaers.datamigrator.MedicalDeviceDataMigrator.java

/**
 * Will associate the medical devices to Study device after creating equivalent
 * StudyDevices (of type other).  //from   w w w. j ava2 s.co m
 * Step 1: Find the study, and medical device projection.
 * Step 2: Create unique study device per-study
 * Step 3: Associate Medical Device to Study Device
 * @param context
 */

//NOTE : BJ : Assumed that the number of records to migrate will be less than 100. 
@Override
public void migrate(CaaersDataMigrationContext context) {
    String query = "select so.study_id, md.id, md.brand_name, md.common_name, md.device_type,md.manufacturer_name, "
            + "md.manufacturer_city, md.manufacturer_state, md.model_number, md.catalog_number "
            + "from ae_medical_devices  md " + "join ae_reports r on r.id = md.report_id "
            + "join ae_reporting_periods rp on rp.id = r.reporting_period_id "
            + "join participant_assignments a on rp.assignment_id=a.id "
            + "join study_organizations so on so.id = a.study_site_id " + "order by so.study_id";

    HashMap<String, ArrayList<StudyDeviceWrapper>> studyDeviceMap = (HashMap<String, ArrayList<StudyDeviceWrapper>>) getJdbcTemplate()
            .query(query, new ResultSetExtractor() {
                public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
                    //a data structure to hold the merged study device -to- medical device mapping.
                    final HashMap<String, ArrayList<StudyDeviceWrapper>> studyDeviceMap = new HashMap<String, ArrayList<StudyDeviceWrapper>>();
                    String studyId = null;
                    ArrayList<StudyDeviceWrapper> studyDeviceWrapperList = null;
                    while (rs.next()) {

                        studyId = getString(rs, 1);
                        String mdId = getString(rs, 2);

                        StudyDevice sd = new StudyDevice();
                        sd.setOtherBrandName(getString(rs, 3));
                        sd.setOtherCommonName(getString(rs, 4));
                        sd.setOtherDeviceType(getString(rs, 5));
                        sd.setManufacturerName(getString(rs, 6));
                        sd.setManufacturerCity(getString(rs, 7));
                        sd.setManufacturerState(getString(rs, 8));
                        sd.setModelNumber(getString(rs, 9));
                        sd.setCatalogNumber(getString(rs, 10));

                        studyDeviceWrapperList = studyDeviceMap.get(studyId);
                        if (studyDeviceWrapperList == null) {
                            //new study 
                            studyDeviceWrapperList = new ArrayList<StudyDeviceWrapper>();
                            studyDeviceMap.put(studyId, studyDeviceWrapperList);
                        }
                        StudyDeviceWrapper wrapper = StudyDeviceWrapper
                                .findStudyDeviceWrapper(studyDeviceWrapperList, sd);
                        if (wrapper == null) {
                            //new study device
                            wrapper = new StudyDeviceWrapper(studyId, sd, mdId);
                            studyDeviceWrapperList.add(wrapper);
                        } else {
                            //merge to existing study device
                            wrapper.addMedicalDeviceId(mdId);
                        }

                    }
                    return studyDeviceMap;
                }

                //some PostgresSQL driver will throw NPE when column is SQL NULL
                // so this workaround....
                public String getString(ResultSet rs, int index) throws SQLException {
                    Object o = rs.getObject(index);
                    if (o == null)
                        return null;
                    return String.valueOf(o);
                }
            });

    //now generate the batch statements.
    ArrayList<String> sqls = new ArrayList<String>();
    for (String key : studyDeviceMap.keySet()) {
        ArrayList<StudyDeviceWrapper> wrapperList = studyDeviceMap.get(key);
        for (StudyDeviceWrapper wrapper : wrapperList) {
            sqls.add(generateInsertStudyDeviceSQL(context, wrapper)); //insert study device.
            sqls.addAll(generateUpdateMedicalDeviceSQL(wrapper)); // scripts to udpate the medical device
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("SQLs to run [MedicalDeviceDataMigrator] ...");
        for (String sql : sqls)
            log.debug(" >>> " + sql);
    }
    if (!sqls.isEmpty())
        getJdbcTemplate().batchUpdate(sqls.toArray(new String[] {}));
}

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

/**
 * Handles grouping using resolution handlers to add report date based on chosen resolution
 *//*from www  .  j a va  2  s.com*/
protected Record createRecord(final List<Dimension> queryDimensions, final ResultSet rs,
        final List<DimensionBean> groupingDimensions, final List<ResolutionHandler> handlers,
        final List<Integer> colAddedCounts) throws SQLException {
    final Map<String, Dimension> dimensions = new LinkedHashMap<String, Dimension>(
            queryDimensions.size() + groupingDimensions.size());
    final Map<String, Object> values = new LinkedHashMap<String, Object>(
            queryDimensions.size() + groupingDimensions.size());

    int colCount = 0;
    for (int i = 0; i < queryDimensions.size(); i++) {
        final Dimension d = queryDimensions.get(i);
        dimensions.put(d.getId(), d);
        values.put(d.getId(), DataTypeConversionHelper.convert2JavaType(rs, d.getSqlType(), i + 1 + 0));
        colCount++;
    }

    for (int i = 0; i < groupingDimensions.size(); i += 1) {
        ResolutionHandler handler = handlers.get(i);
        DimensionBean dim = groupingDimensions.get(i);
        dimensions.put(dim.getId(), new DimensionBeanAdapter(dim, JdbcOeDataSource.this));

        if (handler == null) {
            values.put(dim.getId(), DataTypeConversionHelper.convert2JavaType(rs, dim.getSqlType(), colCount));
            colCount += 1;
        } else {
            int size = colAddedCounts.get(i);
            Object[] vals = new Object[size];
            for (int j = 0; j < size; j += 1) {
                vals[j] = rs.getObject(colCount + 1 + j);
            }
            colCount += size;
            Object kernelObj;
            try {
                kernelObj = handler.buildKernel(vals);
            } catch (OeDataSourceException e) {
                throw new SQLException(e);
            }
            values.put(dim.getId(), kernelObj);
        }
    }
    return new QueryRecord(dimensions, values);
}

From source file:com.chiorichan.database.DatabaseEngine.java

public static Map<String, Object> convertRow(ResultSet rs) throws SQLException {
    Map<String, Object> result = Maps.newLinkedHashMap();
    ResultSetMetaData rsmd = rs.getMetaData();

    int numColumns = rsmd.getColumnCount();

    for (int i = 1; i < numColumns + 1; i++) {
        String columnName = rsmd.getColumnName(i);

        // Loader.getLogger().info( "Column: " + columnName + " <-> " + rsmd.getColumnTypeName( i ) );

        if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) {
            result.put(columnName, rs.getArray(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BIT) // Sometimes tinyints are read as bits
        {//from   w  w  w  . j  a va  2  s.  c  om
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) {
            result.put(columnName, rs.getBoolean(columnName));
        } else if (rsmd.getColumnTypeName(i).contains("BLOB")
                || rsmd.getColumnType(i) == java.sql.Types.BINARY) {
            // BLOG = Max Length 65,535. Recommended that you use a LONGBLOG.
            byte[] bytes = rs.getBytes(columnName);
            result.put(columnName, bytes);
            /*
             * try
             * {
             * result.put( columnName, new String( bytes, "ISO-8859-1" ) );
             * }
             * catch ( UnsupportedEncodingException e )
             * {
             * e.printStackTrace();
             * }
             */
        } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) {
            result.put(columnName, rs.getDouble(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) {
            result.put(columnName, rs.getFloat(columnName));
        } else if (rsmd.getColumnTypeName(i).equals("INT")) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) {
            result.put(columnName, rs.getNString(columnName));
        } else if (rsmd.getColumnTypeName(i).equals("VARCHAR")) {
            result.put(columnName, rs.getString(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) {
            result.put(columnName, rs.getInt(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) {
            result.put(columnName, rs.getDate(columnName));
        } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) {
            result.put(columnName, rs.getTimestamp(columnName));
        } else {
            result.put(columnName, rs.getObject(columnName));
        }
    }

    return result;
}

From source file:com.squid.kraken.v4.caching.redis.datastruct.RawMatrix.java

public static RawMatrixStreamExecRes streamExecutionItemToByteArray(IExecutionItem item,
        long nbLinesExpectedLeft) throws IOException, SQLException {

    RawMatrixStreamExecRes res = new RawMatrixStreamExecRes();
    long metter_start = System.currentTimeMillis();
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    Output kout = new Output(baout);

    Kryo kryo = new Kryo();
    kryo.setRegistrationRequired(true);//ww w .j av  a2s . c om
    kryo.setReferences(false);

    ResultSet result = item.getResultSet();
    IJDBCDataFormatter formatter = item.getDataFormatter();
    //
    // if(logger.isDebugEnabled()){logger.debug(("Formatter
    // ="+formatter.getClass().toString()));}

    ResultSetMetaData metadata = result.getMetaData();
    int nbColumns = metadata.getColumnCount();

    IVendorSupport vendorSpecific = VendorSupportRegistry.INSTANCE.getVendorSupport(item.getDatabase());

    int[] colTypes = vendorSpecific.getVendorMetadataSupport().normalizeColumnType(result);

    // get columns #, type and names
    String[] colNames = new String[nbColumns];
    int i = 0;
    while (i < nbColumns) {
        colNames[i] = metadata.getColumnLabel(i + 1);
        i++;
    }
    // register
    // Class mapping have to be registered before we start writing
    HashMap<String, Integer> registration = new HashMap<String, Integer>();
    for (int val : colTypes) {
        if (!isPrimitiveType(val)) {
            String className = getJavaDatatype(val);
            try {
                if (registration.get(className) == null) {
                    registration.put(className, kryo.register(Class.forName(className)).getId());
                }
            } catch (ClassNotFoundException e0) {
                logger.info("Class " + className + " not found");
            } catch (NullPointerException e1) {
                logger.info("Class " + className + " not found");
            }
        }
    }

    // Register Hadoop type
    // registration.put("org.apache.hadoop.io.Text",kryo.register(org.apache.hadoop.io.Text.class).getId());
    // registration.put("byte[]", kryo.register(byte[].class).getId());

    // start writing!

    // registration
    kout.writeInt(registration.keySet().size());
    for (String s : registration.keySet()) {
        kout.writeString(s);
        kout.writeInt(registration.get(s));
        // logger.info(s + " " + registration.get(s));
    }

    // version
    int version = VERSION;
    if (version >= 1) {
        kout.writeInt(-1);// this is for V0 compatibility which miss
        // version information
        kout.writeInt(version);
    }

    // Redis cache type
    kout.writeInt(RedisCacheType.RAW_MATRIX.ordinal());

    // nb of columns
    kout.writeInt(nbColumns);

    // columns names
    for (String n : colNames)
        kout.writeString(n);

    // column type
    for (Integer t : colTypes)
        kout.writeInt(t);

    // rows
    // we need a different dictionary to check for first occurences
    HashMap<String, Integer> tempsDict = new HashMap<String, Integer>();
    int count = 0;
    int index = 0;
    boolean moreData = false;
    boolean maxSizeReached = false;

    while ((!maxSizeReached) && (moreData = result.next())) {
        i = 0;
        kout.writeBoolean(true);
        while (i < nbColumns) {
            Object value = result.getObject(i + 1);
            Object unbox = formatter.unboxJDBCObject(value, colTypes[i]);
            // if(logger.isDebugEnabled()){logger.debug(("unbox value is
            // "+unbox));}
            if (unbox instanceof String) {
                String stringVal = (String) unbox;
                // System.out.println(stringVal);
                Integer ref = tempsDict.get(stringVal);
                if (ref != null) {
                    kout.write(MEMBER_REFERENCE);// 4
                    kout.writeInt(ref);// 5
                } else {
                    kout.write(MEMBER_DEFINITION);// 4
                    kout.writeString(stringVal);
                    tempsDict.put(stringVal, new Integer(index));
                    index++;
                }
            } else {
                kout.write(MEMBER_VALUE);// 4
                // if(logger.isDebugEnabled()){logger.debug(("member
                // unbox " + unbox.toString()));}
                // if(logger.isDebugEnabled()){logger.debug(("member
                // value " + value.toString()));}
                kryo.writeClassAndObject(kout, unbox);
            }
            i++;
        }

        count++;

        // stats: display time for first 100th rows
        if (count == 100) {
            long intermediate = new Date().getTime();
            // logger.info("SQLQuery#" + item.getID() + " proceeded
            // first 100 items in "+(intermediate-metter_start)+" ms");
            logger.info("task=RawMatrix" + " method=streamExecutionItemToByteArray" + " duration="
                    + ((intermediate - metter_start)) + " error=false status=running queryid=" + item.getID());

        }
        // if max chunk size of 50MB reached, stop 
        if (count % 100 == 0) {
            float size = Math.round(baout.size() / 1048576);
            if (size >= maxChunkSizeInMB) {
                logger.info("Max size of " + maxChunkSizeInMB + "MB for one chunk reached");
                maxSizeReached = true;
            }
        }

        // DEBUG CODE TO CREATE SMALLER CHUNKS
        /*      if (count == 250){
                 maxSizeReached= true;
        //            logger.info("Max debug size of 250 items reached");
              }  */
    }

    // WRITE moredata
    kout.writeBoolean(false);// close the data stream, begin metadata

    //we stop either if maxSize was reach or if there were no more data to read
    boolean moreToRead = false; // we did not reach the end of the resultset
    boolean moreThanLimit = false; // is case of a limit query, did we reach the limit
    if (maxSizeReached) { // we  stopped because reached the hard memory limit for one chunk
        if ((nbLinesExpectedLeft > -1) && (!(count < nbLinesExpectedLeft))) { //we read exqctly as many lines as the limit
            moreThanLimit = true;
        } else {
            moreThanLimit = true;
            moreToRead = true;
        }
    } else {
        if (!moreData) { //no more lines to read
            if (nbLinesExpectedLeft > -1) { // limit
                if (!(count < nbLinesExpectedLeft)) { //we read as many lines as the limit
                    moreThanLimit = true;
                }
            }
        }
    }

    kout.writeBoolean(moreThanLimit);
    // -- V1 only
    if (version >= 1) {
        kout.writeLong(item.getExecutionDate().getTime());// the
        // computeDate
    }

    // stats: display total
    long metter_finish = new Date().getTime();
    // logger.info("SQLQuery#" + item.getID() + " serialized
    // "+(count-1)+" row(s) in "+(metter_finish-metter_start)+" ms,
    // compressed resulset size is "+size+" Mbytes");
    /*   logger.info("task=RawMatrix" + " method=streamExecutionItemToByteArray" + " duration="
    + (metter_finish - metter_start) / 1000 + " error=false status=done driver="
    + item.getDatabase().getName() + " queryid=" + item.getID() + " size= " + size + " SQLQuery#"
    + item.getID() + " serialized " + (count - 1) + " row(s) in " + (metter_finish - metter_start)
    + " ms, compressed resulset size is " + size + " Mbytes"); */
    // TODO Get project
    SQLStats queryLog = new SQLStats(Integer.toString(item.getID()), "streamExecutionItemToByteArray", "",
            (metter_finish - metter_start), item.getDatabase().getName());
    queryLog.setError(false);
    PerfDB.INSTANCE.save(queryLog);

    kout.close();

    res.setHasMore(moreToRead);
    res.setExecutionTime(metter_finish - metter_start);
    res.setNbLines(count);
    res.setStreamedMatrix(baout.toByteArray());

    return res;

}

From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java

@Test
public void testDoubleFloat() throws SQLException, IOException {
    trace("test DOUBLE - FLOAT");

    ResultInHBasePrinter.printFMETA(TEST_UTIL.getConfiguration(), LOG);
    ResultInHBasePrinter.printMETA(TEST_UTIL.getConfiguration(), LOG);
    ResultSet rs;
    Object o;// w w  w  .  ja v  a  2 s  . c o  m

    stat = conn.createStatement();
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(11, -1, -1, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(12,.0, .0, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(13, 1., 1., 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(14, 12345678.89, 12345678.89, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(15, 99999999.99, 99999999.99, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(16, -99999999.99, -99999999.99, 2, 'testDoubleFloat')");
    stat.execute(
            "INSERT INTO test (column1,column5,column4,column2,column3) VALUES(17, -99999999.99, -99999999.99, 2, 'testDoubleFloat')");
    // stat.execute("INSERT INTO test (column1,column5,column4,column2,column3) VALUES(8, NULL, NULL, 2, 'testDoubleFloat')");

    rs = stat.executeQuery(
            "SELECT column1,column5,column4 FROM test where column3='testDoubleFloat'  ORDER BY column1");
    // assertResultSetMeta(rs, 3, new String[] { "ID", "D", "R" }, new int[] {
    // Types.INTEGER, Types.DOUBLE, Types.REAL }, new int[] { 10, 17, 7 },
    // new int[] { 0, 0, 0 });
    BigDecimal bd;
    rs.next();
    assertTrue(rs.getInt(1) == 11);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(2) == -1);
    assertTrue(rs.getInt(3) == -1);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(2);
    assertTrue(bd.compareTo(new BigDecimal("-1.00")) == 0);
    assertTrue(!rs.wasNull());
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Double);
    assertTrue(((Double) o).compareTo(new Double("-1.00")) == 0);
    o = rs.getObject(3);
    trace(o.getClass().getName());
    assertTrue(o instanceof Float);
    assertTrue(((Float) o).compareTo(new Float("-1.00")) == 0);
    rs.next();
    assertTrue(rs.getInt(1) == 12);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(2) == 0);
    assertTrue(!rs.wasNull());
    assertTrue(rs.getInt(3) == 0);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(2);
    assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
    assertTrue(!rs.wasNull());
    bd = rs.getBigDecimal(3);
    assertTrue(bd.compareTo(new BigDecimal("0.00")) == 0);
    assertTrue(!rs.wasNull());
    rs.next();
    assertEquals(1.0, rs.getDouble(2));
    assertEquals(1.0f, rs.getFloat(3));
    rs.next();
    assertEquals(12345678.89, rs.getDouble(2));
    assertEquals(12345678.89f, rs.getFloat(3));
    rs.next();
    assertEquals(99999999.99, rs.getDouble(2));
    assertEquals(99999999.99f, rs.getFloat(3));
    rs.next();
    assertEquals(-99999999.99, rs.getDouble(2));
    assertEquals(-99999999.99f, rs.getFloat(3));
    // rs.next();
    // checkColumnBigDecimal(rs, 2, 0, null);
    // checkColumnBigDecimal(rs, 3, 0, null);
    // assertTrue(!rs.next());
    // stat.execute("DROP TABLE test");
}

From source file:org.zenoss.zep.dao.impl.EventSummaryDaoImpl.java

private int update(final List<String> uuids, final EventStatus status,
        final EventSummaryUpdateFields updateFields, final Collection<EventStatus> currentStatuses)
        throws ZepException {
    if (uuids.isEmpty()) {
        return 0;
    }//  www  .j  ava  2 s .c  om
    TypeConverter<Long> timestampConverter = databaseCompatibility.getTimestampConverter();
    final long now = System.currentTimeMillis();
    final Map<String, Object> fields = updateFields.toMap(uuidConverter);
    fields.put(COLUMN_STATUS_ID, status.getNumber());
    fields.put(COLUMN_STATUS_CHANGE, timestampConverter.toDatabaseType(now));
    fields.put(COLUMN_CLOSED_STATUS, ZepConstants.CLOSED_STATUSES.contains(status));
    fields.put(COLUMN_UPDATE_TIME, timestampConverter.toDatabaseType(now));
    fields.put("_uuids", TypeConverterUtils.batchToDatabaseType(uuidConverter, uuids));
    // If we aren't acknowledging events, we need to clear out the current user name / UUID values
    if (status != EventStatus.STATUS_ACKNOWLEDGED) {
        fields.put(COLUMN_CURRENT_USER_NAME, null);
        fields.put(COLUMN_CURRENT_USER_UUID, null);
    }

    StringBuilder sb = new StringBuilder("SELECT uuid,fingerprint,audit_json FROM event_summary");
    StringBuilder sbw = new StringBuilder(" WHERE uuid IN (:_uuids)");
    /*
     * This is required to support well-defined transitions between states. We only allow
     * updates to move events between states that make sense.
     */
    if (!currentStatuses.isEmpty()) {
        final List<Integer> currentStatusIds = new ArrayList<Integer>(currentStatuses.size());
        for (EventStatus currentStatus : currentStatuses) {
            currentStatusIds.add(currentStatus.getNumber());
        }
        fields.put("_current_status_ids", currentStatusIds);
        sbw.append(" AND status_id IN (:_current_status_ids)");
    }
    /*
     * Disallow acknowledging an event again as the same user name / user uuid. If the event is not
     * already acknowledged, we will allow it to be acknowledged (assuming state filter above doesn't
     * exclude it). Otherwise, we will only acknowledge it again if *either* the user name or user
     * uuid has changed. If neither of these fields have changed, it is a NO-OP.
     */
    if (status == EventStatus.STATUS_ACKNOWLEDGED) {
        fields.put("_status_acknowledged", EventStatus.STATUS_ACKNOWLEDGED.getNumber());
        sbw.append(" AND (status_id != :_status_acknowledged OR ");
        if (updateFields.getCurrentUserName() == null) {
            sbw.append("current_user_name IS NOT NULL");
        } else {
            sbw.append("(current_user_name IS NULL OR current_user_name != :current_user_name)");
        }
        sbw.append(" OR ");
        if (updateFields.getCurrentUserUuid() == null) {
            sbw.append("current_user_uuid IS NOT NULL");
        } else {
            sbw.append("(current_user_uuid IS NULL OR current_user_uuid != :current_user_uuid)");
        }
        sbw.append(")");
    }
    String selectSql = sb.toString() + sbw.toString() + " FOR UPDATE";

    final long updateTime = System.currentTimeMillis();
    final String indexSql = "INSERT INTO event_summary_index_queue (uuid, update_time) " + "SELECT uuid, "
            + String.valueOf(updateTime) + " " + "FROM event_summary " + sbw.toString();
    this.template.update(indexSql, fields);

    /*
     * If this is a significant status change, also add an audit note
     */
    final String newAuditJson;
    if (AUDIT_LOG_STATUSES.contains(status)) {
        EventAuditLog.Builder builder = EventAuditLog.newBuilder();
        builder.setTimestamp(now);
        builder.setNewStatus(status);
        if (updateFields.getCurrentUserUuid() != null) {
            builder.setUserUuid(updateFields.getCurrentUserUuid());
        }
        if (updateFields.getCurrentUserName() != null) {
            builder.setUserName(updateFields.getCurrentUserName());
        }
        try {
            newAuditJson = JsonFormat.writeAsString(builder.build());
        } catch (IOException e) {
            throw new ZepException(e);
        }
    } else {
        newAuditJson = null;
    }

    List<Map<String, Object>> result = this.template.query(selectSql, new RowMapper<Map<String, Object>>() {
        @Override
        public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
            final String fingerprint = rs.getString(COLUMN_FINGERPRINT);
            final String currentAuditJson = rs.getString(COLUMN_AUDIT_JSON);

            Map<String, Object> updateFields = new HashMap<String, Object>(fields);
            final String newFingerprint;
            // When closing an event, give it a unique fingerprint hash
            if (ZepConstants.CLOSED_STATUSES.contains(status)) {
                updateFields.put(COLUMN_CLOSED_STATUS, Boolean.TRUE);
                newFingerprint = EventDaoUtils.join('|', fingerprint, Long.toString(now));
            }
            // When re-opening an event, give it the true fingerprint_hash. This is required to correctly
            // de-duplicate events.
            else {
                updateFields.put(COLUMN_CLOSED_STATUS, Boolean.FALSE);
                newFingerprint = fingerprint;
            }

            final StringBuilder auditJson = new StringBuilder();
            if (newAuditJson != null) {
                auditJson.append(newAuditJson);
            }
            if (currentAuditJson != null) {
                if (auditJson.length() > 0) {
                    auditJson.append(",\n");
                }
                auditJson.append(currentAuditJson);
            }
            String updatedAuditJson = (auditJson.length() > 0) ? auditJson.toString() : null;
            updateFields.put(COLUMN_FINGERPRINT_HASH, DaoUtils.sha1(newFingerprint));
            updateFields.put(COLUMN_AUDIT_JSON, updatedAuditJson);
            updateFields.put(COLUMN_UUID, rs.getObject(COLUMN_UUID));
            return updateFields;
        }
    }, fields);

    final String updateSql = "UPDATE event_summary SET status_id=:status_id,status_change=:status_change,"
            + "closed_status=:closed_status,update_time=:update_time,"
            + (status != EventStatus.STATUS_CLOSED && status != EventStatus.STATUS_CLEARED
                    ? "current_user_uuid=:current_user_uuid,current_user_name=:current_user_name,"
                    : "")
            + "cleared_by_event_uuid=:cleared_by_event_uuid,fingerprint_hash=:fingerprint_hash,"
            + "audit_json=:audit_json WHERE uuid=:uuid";

    int numRows = 0;
    for (final Map<String, Object> update : result) {
        try {
            numRows += this.nestedTransactionService
                    .executeInNestedTransaction(new NestedTransactionCallback<Integer>() {
                        @Override
                        public Integer doInNestedTransaction(NestedTransactionContext context)
                                throws DataAccessException {
                            return template.update(updateSql, update);
                        }
                    });
        } catch (DuplicateKeyException e) {
            /*
             * Ignore duplicate key errors on update. This will occur if there is an active
             * event with the same fingerprint.
             */
        }
    }
    return numRows;
}

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

public static String getCompanyDetails(Connection conn, HttpServletRequest request) throws ServiceException {
    String result = null;/*from   w  w w . j  a v a2  s  .  c  o m*/
    int notificationtype = 0;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    ResultSet rs1 = null;
    JSONObject res = new JSONObject();
    try {
        pstmt = conn.prepareStatement("SELECT companyid,companyname,createdon,address,"
                + "city,state,country,phone,fax,zip,timezone,website,activated,maxusers,"
                + "maxprojects,image,featureaccess,planid,subscriptiondate,payerid,emailid,"
                + "creator,modifiedon,isexpired,maxcommunities,currency,subdomain,"
                + "notificationtype,milestonewidget,checklist,docaccess FROM company WHERE companyid = ?");
        pstmt.setString(1, request.getParameter("cid"));
        rs = pstmt.executeQuery();
        while (rs.next()) {
            JSONObject temp = new JSONObject();
            temp.put("companyid", rs.getString("companyid"));
            temp.put("companyname", rs.getObject("companyname"));
            temp.put("createdon", rs.getObject("createdon").toString());
            temp.put("address", rs.getObject("address"));
            temp.put("city", rs.getObject("city"));
            temp.put("state", rs.getObject("state"));
            String country = getCmpCountry(conn, rs.getString("country"));
            temp.put("country", country);
            temp.put("phone", rs.getObject("phone"));
            temp.put("fax", rs.getObject("fax"));
            temp.put("zip", rs.getObject("zip"));
            String tz = getCmpTz(conn, rs.getString("timezone"));
            temp.put("timezone", tz);
            temp.put("website", rs.getObject("website"));
            temp.put("activated", rs.getObject("activated"));
            temp.put("image", rs.getObject("image"));
            temp.put("featureaccess", rs.getObject("featureaccess"));
            temp.put("planid", rs.getObject("planid"));
            temp.put("subscriptiondate", rs.getObject("subscriptiondate"));
            temp.put("payerid", rs.getObject("payerid"));
            temp.put("emailid", rs.getObject("emailid"));
            temp.put("creator", rs.getObject("creator"));
            temp.put("modifiedon", rs.getObject("modifiedon"));
            temp.put("isexpired", rs.getObject("isexpired"));
            temp.put("maxcommunities", rs.getObject("maxcommunities"));
            temp.put("milestonewidget", rs.getObject("milestonewidget"));
            temp.put("checklist", rs.getObject("checklist"));
            temp.put("docaccess", rs.getObject("docaccess"));
            String curr = getCmpCurr(conn, rs.getString("currency"));
            temp.put("currency", curr);
            temp.put("subdomain", rs.getObject("subdomain"));
            notificationtype = rs.getInt("notificationtype");
            DbResults r = DbUtil.executeQuery(conn,
                    "SELECT o_diff, p_diff FROM pertdefaults_company WHERE companyid = ?",
                    request.getParameter("cid"));
            if (r.next()) {
                temp.put("optimisticdiff", r.getInt("o_diff"));
                temp.put("pessimisticdiff", r.getInt("p_diff"));
            }
            //      temp.put("notificationduration", rs.getObject("notificationduration"));
            res.append("data", temp);
        }
        pstmt = conn.prepareStatement("SELECT typeid from notificationlist");
        rs1 = pstmt.executeQuery();
        JSONObject alltype = new JSONObject();
        while (rs1.next()) {
            JSONObject temp = new JSONObject();
            int tempInt = rs1.getInt("typeid");
            temp.put("typeid", tempInt);
            int actid = (int) Math.pow(2, rs1.getInt("typeid"));
            if ((notificationtype & actid) == actid) {
                temp.put("permission", true);
            } else {
                temp.put("permission", false);
            }
            alltype.append("data", temp);
        }
        res.append("notification", alltype);
        result = res.toString();
    } catch (SQLException e) {
        throw ServiceException.FAILURE("Admin.getCompanyDetails", e);
    } catch (Exception ex) {
        throw ServiceException.FAILURE("Admin.getCompanyDetails", ex);
    } finally {
        DbPool.closeStatement(pstmt);
    }
    return result;
}

From source file:com.nextep.designer.dbgm.services.impl.DataService.java

private void saveDataLinesToRepository(IDataSet dataSet, IDataSet dataSetContents, DeltaType deltaType,
        IProgressMonitor monitor) {/*  w  w  w.  ja va  2  s. co  m*/
    final SubMonitor m = SubMonitor.convert(monitor, 10000);
    m.subTask(MessageFormat.format(DBGMMessages.getString("service.data.dataSetSaveInit"), dataSet.getName())); //$NON-NLS-1$
    IStorageHandle handle = dataSetContents.getStorageHandle();
    if (handle == null) {
        handle = storageService.createDataSetStorage(dataSet);
    }

    Connection derbyConn = null;
    Statement stmt = null;
    ResultSet rset = null;
    Connection repoConn = null;
    PreparedStatement insertStmt = null;
    Session s = null;
    Transaction t = null;
    long rowid = dataSet.getCurrentRowId() + 1;
    try {
        repoConn = getRepositoryConnection();
        repoConn.setAutoCommit(false);

        // We handle the Hibernate session specifically to boost the import process
        s = HibernateUtil.getInstance().getSandBoxSession();
        s.clear();
        t = s.beginTransaction();
        // Our prepared INSERT rows statement
        insertStmt = repoConn.prepareStatement("INSERT INTO dbgm_dset_row_values ( " //$NON-NLS-1$
                + "  drow_id, column_refid, column_value " //$NON-NLS-1$
                + ") VALUES ( " //$NON-NLS-1$
                + "  ?, ?, ? " //$NON-NLS-1$
                + ") "); //$NON-NLS-1$

        // Getting our local derby connection
        derbyConn = storageService.getLocalConnection();
        stmt = derbyConn.createStatement();

        // Selecting data from derby local storage
        String selectStmt = handle.getSelectStatement();
        selectStmt = selectStmt.replace("SELECT", "SELECT " + IStorageService.ROWID_COLUMN_NAME //$NON-NLS-1$ //$NON-NLS-2$
                + ","); //$NON-NLS-1$
        rset = stmt.executeQuery(selectStmt);
        final List<IReference> colRefs = dataSet.getColumnsRef();

        int lineBufferCount = 0;
        long counter = 0;
        while (rset.next()) {
            final IDataLine line = typedObjectFactory.create(IDataLine.class);
            line.setDataSet(dataSet);
            // If we got a repository rowid, we use it, else we affect a new available rowid
            final long selectedRowId = rset.getLong(1);
            if (selectedRowId != 0) {
                line.setRowId(selectedRowId);
            } else {
                line.setRowId(rowid++);
            }
            // Persisting line so that columns can use its ID
            s.save(line);
            if (deltaType != DeltaType.DELETE) {
                for (int i = 2; i < colRefs.size() + 2; i++) {
                    final Object val = rset.getObject(i);
                    // First column is our rowid, so we shift left by 1, starting at 0 => -2
                    final IReference colRef = colRefs.get(i - 2);
                    final IColumnValue colValue = typedObjectFactory.create(IColumnValue.class);
                    colValue.setDataLine(line);
                    colValue.setColumnRef(colRef);
                    colValue.setValue(val);
                    line.addColumnValue(colValue);
                    insertStmt.setLong(1, line.getUID().rawId());
                    insertStmt.setLong(2, colRef.getUID().rawId());
                    insertStmt.setString(3, colValue.getStringValue());
                    insertStmt.addBatch();
                }
            }
            if (lineBufferCount++ >= LINE_BUFFER_SIZE) {
                t.commit();
                insertStmt.executeBatch();
                s.clear();
                t = s.beginTransaction();
                counter += lineBufferCount;
                m.subTask(MessageFormat.format(DBGMMessages.getString("service.data.savedLines"), //$NON-NLS-1$
                        dataSet.getName(), counter));
                m.worked(500);
                lineBufferCount = 0;
            }
        }
        if (lineBufferCount > 0) {
            t.commit();
            insertStmt.executeBatch();
            s.clear();
            lineBufferCount = 0;
        }
        repoConn.commit();
        dataSet.setCurrentRowId(rowid);
    } catch (SQLException e) {
        throw new ErrorException(DBGMMessages.getString("service.data.saveDatalineFailed") + e.getMessage(), e); //$NON-NLS-1$
    } finally {
        safeClose(rset, stmt, derbyConn, false);
        safeClose(null, insertStmt, repoConn, true);
    }
}

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  ava2 s .co 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());
}