Example usage for java.sql ResultSet TYPE_SCROLL_SENSITIVE

List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE

Introduction

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

Prototype

int TYPE_SCROLL_SENSITIVE

To view the source code for java.sql ResultSet TYPE_SCROLL_SENSITIVE.

Click Source Link

Document

The constant indicating the type for a ResultSet object that is scrollable and generally sensitive to changes to the data that underlies the ResultSet.

Usage

From source file:io.cloudslang.content.database.utils.SQLInputsUtilsTest.java

@Test
public void getResultSetTypeSimple() throws Exception {
    assertEquals(ResultSet.TYPE_FORWARD_ONLY, getResultSetType(TYPE_FORWARD_ONLY));
    assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE, getResultSetType(TYPE_SCROLL_INSENSITIVE));
    assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, getResultSetType(TYPE_SCROLL_SENSITIVE));
}

From source file:com.tascape.qa.th.db.H2Handler.java

@Override
public void updateSuiteExecutionResult(String execId) throws SQLException {
    LOG.info("Update test suite execution result with execution id {}", execId);
    int total = 0, fail = 0;

    try (Connection conn = this.getConnection();) {
        final String sql1 = "SELECT " + Test_Result.EXECUTION_RESULT.name() + " FROM " + TestResult.TABLE_NAME
                + " WHERE " + Test_Result.SUITE_RESULT.name() + " = ?;";
        try (PreparedStatement stmt = conn.prepareStatement(sql1)) {
            stmt.setString(1, execId);/* www. j a  v  a2 s .  c om*/
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                total++;
                String result = rs.getString(Test_Result.EXECUTION_RESULT.name());
                if (!result.equals(ExecutionResult.PASS.name()) && !result.endsWith("/0")) {
                    fail++;
                }
            }
        }
    }

    try (Connection conn = this.getConnection();) {
        final String sql = "SELECT * FROM " + SuiteResult.TABLE_NAME + " WHERE " + SuiteResult.SUITE_RESULT_ID
                + " = ?;";
        try (PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE)) {
            stmt.setString(1, execId);
            ResultSet rs = stmt.executeQuery();
            if (rs.first()) {
                rs.updateInt(SuiteResult.NUMBER_OF_TESTS, total);
                rs.updateInt(SuiteResult.NUMBER_OF_FAILURE, fail);
                rs.updateString(SuiteResult.EXECUTION_RESULT, fail == 0 ? "PASS" : "FAIL");
                rs.updateLong(SuiteResult.STOP_TIME, System.currentTimeMillis());
                rs.updateRow();
            }
        }
    }
}

From source file:ubc.pavlab.aspiredb.server.service.ProjectServiceImpl.java

/**
 * @author gaya//from   ww  w. ja  va2  s .c o m
 * @param fileContent
 * @param projectName
 * @param variantType
 * @return Error String
 */
@Override
@RemoteMethod
public VariantUploadServiceResult addSubjectVariantsToProject(String filepath, boolean createProject,
        String projectName, String variantType, final boolean dryRun) throws Exception {

    Class.forName("org.relique.jdbc.csv.CsvDriver");

    File file = new File(filepath);
    String filename = file.getName();

    if (!file.exists()) {
        throw new IllegalArgumentException("File " + filepath + " not found");
    }

    if (filename.endsWith(".csv")) {
        filename = filename.substring(0, file.getName().length() - 4);
    } else {
        throw new IllegalArgumentException("File not processed, file name must end with .csv");
    }

    // create a connection
    // arg[0] is the directory in which the .csv files are held
    Properties props = new Properties();
    props.put("trimHeaders", "true");
    props.put("trimValues", "true");
    Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + file.getParentFile().getAbsolutePath(),
            props);

    Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet results = stmt.executeQuery("SELECt * from " + filename);

    // check weather the project exist
    if (createProject) {
        if (projectDao.findByProjectName(projectName) != null) {
            throw new IllegalArgumentException("Project " + projectName
                    + " already exists, choose a different project name or use existingproject option to add to this project.");
        } else {
            projectManager.createProject(projectName, "");
        }
    }

    VariantUploadServiceResult result = null;

    if (variantType.equalsIgnoreCase("CNV")) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.CNV);
    } else if (variantType.equalsIgnoreCase("SNV")) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.SNV);
    } else if (variantType.equalsIgnoreCase("INDEL")) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.INDEL);
    } else if (variantType.equalsIgnoreCase("INVERSION")) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.INVERSION);
    } else if (variantType.equalsIgnoreCase(SpecialProject.DECIPHER.toString())) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.DECIPHER);
    } else if (variantType.equalsIgnoreCase(SpecialProject.DGV.toString())) {
        result = VariantUploadService.makeVariantValueObjectsFromResultSet(results, VariantType.DGV);
    }

    if (!result.getErrorMessages().isEmpty()) {
        return result;
    }

    // check if the user is trying to upload too much data
    boolean isSpecialProject = false;
    for (SpecialProject sp : SpecialProject.values()) {
        if (sp.toString().equals(projectName)) {
            isSpecialProject = true;
            break;
        }
    }
    int limit = ConfigUtils.getInt("aspiredb.upload.maxRecords", 10000);
    if (!isSpecialProject && result.getVariantsToAdd().size() > limit) {
        List<String> errorMessages = Collections.singletonList("Upload is limited to " + limit + " variants");
        ArrayList<VariantValueObject> variantsToAdd = new ArrayList<>();
        return new VariantUploadServiceResult(variantsToAdd, errorMessages);
    }

    StopWatch timer = new StopWatch();
    timer.start();

    if (!dryRun) {
        projectManager.addSubjectVariantsToProject(projectName, false, result.getVariantsToAdd());

        log.info("Adding " + result.getVariantsToAdd().size() + " variants to project " + projectName + " took "
                + timer.getTime() + " ms");
    }

    return result;
}

From source file:org.dbinterrogator.mssql.MSSQLInstance.java

/**
 * List Tables/*w  ww . ja  va2 s.c  om*/
 *
 * @param  db  Database Name
 * @return List of tables for selected database
 */
public ArrayList<String> listTables(String db) {
    ArrayList<String> tables = new ArrayList();
    try {
        Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        s.executeQuery("SELECT name FROM [" + db + "].sys.tables");
        ResultSet rs = s.getResultSet();
        while (rs.next()) {
            tables.add(rs.getString(1));
        }
    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }
    if (verbose) {
        System.out.println(tables);
    }
    return tables;
}

From source file:cn.labthink.ReadAccess060.java

private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed

    //filter// w ww.  j  a  va2  s . c om
    ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true);
    filter.setDescription("Open DataBase File");
    //?

    JFileChooser jfc = new JFileChooser();

    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?
    jfc.setCurrentDirectory(fsv.getHomeDirectory());

    jfc.setDialogTitle("Choose the mdb file");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setFileFilter(filter);
    int result = jfc.showOpenDialog(this); // ""?
    if (result == JFileChooser.APPROVE_OPTION) {
        String filesrc = jfc.getSelectedFile().getAbsolutePath();
        inputfile = jfc.getSelectedFile();
        jLabel_dbpath.setText("DB File Path:" + filesrc);
        maxid = Integer.MIN_VALUE;
        minid = Integer.MAX_VALUE;
    } else {
        return;
    }
    //

    Infodata = new Vector();
    Infocolumns = new Vector();

    try {

        //            String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB";
        if (inputfile == null) {
            return;
        }
        initDB();

        sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = sql.executeQuery("SELECT * FROM test order by testid desc");

        Infocolumns.add("TestID");
        Infocolumns.add("TestType");
        Infocolumns.add("DeviceID");
        Infocolumns.add("CellID");
        Infocolumns.add("Operator");
        Infocolumns.add("StartTime");
        Infocolumns.add("EndTime");
        Infocolumns.add("Comments");
        Infocolumns.add("SetTemp.");
        int columnCount = Infocolumns.size();
        Vector row;
        while (rs.next()) {
            row = new Vector(columnCount);
            int temp = 0;
            int ivalue = rs.getInt("TESTID");
            maxid = maxid < ivalue ? ivalue : maxid;
            minid = minid > ivalue ? ivalue : minid;
            row.add(ivalue);
            temp = rs.getInt("TESTTYPE");
            if (temp == 1) {
                row.add("OTR");
            } else if (temp == 2) {
                row.add("WVTR");
            } else {
                row.add(temp);
            }
            row.add(rs.getInt("DEVICEID"));
            row.add(rs.getString("CELLID"));
            row.add(rs.getString("OPERATOR"));
            row.add(rs.getDate("STARTTIME"));
            row.add(rs.getDate("ENDTIME"));
            row.add(rs.getString("COMMENTS"));
            row.add(rs.getDouble("SETTEMP"));
            //                row.add(rs.getString(11));
            //                row.add(rs.getInt(10));
            Infodata.add(row);
        }

        DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns);
        jTable1.setModel(tableModel);
        //?  
        // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);  
        jTable1.setSelectionBackground(Color.orange);
        //?
        TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel);
        jTable1.setRowSorter(tableRowSorter);
        //            jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //table
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table
        tcr.setHorizontalAlignment(SwingConstants.CENTER);// ??
        jTable1.setDefaultRenderer(Object.class, tcr);

        //
        ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer())
                .setHorizontalAlignment(SwingConstants.CENTER);
        //            DefaultTableCellRenderer  rh = new DefaultTableCellRenderer();
        //            rh.setHorizontalAlignment(SwingConstants.CENTER);
        //            jTable1.getTableHeader().setDefaultRenderer(rh);

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(28);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);

    } catch (SQLException ee) {
        System.out.println(ee);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess060.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            sql.close();
        } catch (Exception e) {
        }
        try {
            rs.close();
        } catch (Exception e) {
        }
    }

    //        validate();

}

From source file:cn.labthink.ReadAccess330.java

private void jButton_OpenfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton_OpenfileActionPerformed

    //filter/*from   w w  w. jav  a2  s.com*/
    ExtensionFileFilter filter = new ExtensionFileFilter("mdb", false, true);
    filter.setDescription("Open DataBase File");
    //?

    JFileChooser jfc = new JFileChooser();

    FileSystemView fsv = FileSystemView.getFileSystemView();
    //?
    jfc.setCurrentDirectory(fsv.getHomeDirectory());

    jfc.setDialogTitle("Choose the mdb file");
    jfc.setMultiSelectionEnabled(false);
    jfc.setDialogType(JFileChooser.OPEN_DIALOG);
    jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    jfc.setFileFilter(filter);
    int result = jfc.showOpenDialog(this); // ""?
    if (result == JFileChooser.APPROVE_OPTION) {
        String filesrc = jfc.getSelectedFile().getAbsolutePath();
        inputfile = jfc.getSelectedFile();
        jLabel_dbpath.setText("DB File Path:" + filesrc);
        maxid = Integer.MIN_VALUE;
        minid = Integer.MAX_VALUE;
    } else {
        return;
    }
    //

    Infodata = new Vector();
    Infocolumns = new Vector();

    try {

        //            String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://b.MDB";
        if (inputfile == null) {
            return;
        }
        initDB();

        sql = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        rs = sql.executeQuery("SELECT * FROM test order by testid desc");

        Infocolumns.add("TestID");
        Infocolumns.add("TestType");
        Infocolumns.add("DeviceID");
        Infocolumns.add("CellID");
        Infocolumns.add("Operator");
        Infocolumns.add("StartTime");
        Infocolumns.add("EndTime");
        Infocolumns.add("Comments");
        Infocolumns.add("SetTemp.");
        int columnCount = Infocolumns.size();
        Vector row;
        while (rs.next()) {
            row = new Vector(columnCount);
            int temp = 0;
            int ivalue = rs.getInt("TESTID");
            maxid = maxid < ivalue ? ivalue : maxid;
            minid = minid > ivalue ? ivalue : minid;
            row.add(ivalue);
            temp = rs.getInt("TESTTYPE");
            if (temp == 1) {
                row.add("OTR");
            } else if (temp == 2) {
                row.add("WVTR");
            } else {
                row.add(temp);
            }
            row.add(rs.getInt("DEVICEID"));
            row.add(rs.getString("CELLID"));
            row.add(rs.getString("OPERATOR"));
            row.add(rs.getDate("STARTTIME"));
            row.add(rs.getDate("ENDTIME"));
            row.add(rs.getString("COMMENTS"));
            row.add(rs.getDouble("SETTEMP"));
            //                row.add(rs.getString(11));
            //                row.add(rs.getInt(10));
            Infodata.add(row);
        }

        DefaultTableModel tableModel = new DefaultTableModel(Infodata, Infocolumns);
        jTable1.setModel(tableModel);
        //?  
        // jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);  
        jTable1.setSelectionBackground(Color.orange);
        //?
        TableRowSorter<TableModel> tableRowSorter = new TableRowSorter<TableModel>(tableModel);
        jTable1.setRowSorter(tableRowSorter);
        //            jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //table
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// table
        tcr.setHorizontalAlignment(SwingConstants.CENTER);// ??
        jTable1.setDefaultRenderer(Object.class, tcr);

        //
        ((DefaultTableCellRenderer) jTable1.getTableHeader().getDefaultRenderer())
                .setHorizontalAlignment(SwingConstants.CENTER);
        //            DefaultTableCellRenderer  rh = new DefaultTableCellRenderer();
        //            rh.setHorizontalAlignment(SwingConstants.CENTER);
        //            jTable1.getTableHeader().setDefaultRenderer(rh);

        jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(28);
        jTable1.getColumnModel().getColumn(2).setPreferredWidth(20);
        jTable1.getColumnModel().getColumn(3).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(4).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(5).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(6).setPreferredWidth(100);
        jTable1.getColumnModel().getColumn(7).setPreferredWidth(100);

    } catch (SQLException ee) {
        System.out.println(ee);
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(ReadAccess330.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            sql.close();
        } catch (Exception e) {
        }
        try {
            rs.close();
        } catch (Exception e) {
        }
    }

    //        validate();

}

From source file:org.apache.ambari.server.checks.CheckDatabaseHelper.java

protected void checkHostComponentStatesCountEqualsHostComponentsDesiredStates() {
    String GET_HOST_COMPONENT_STATE_COUNT_QUERY = "select count(*) from hostcomponentstate";
    String GET_HOST_COMPONENT_DESIRED_STATE_COUNT_QUERY = "select count(*) from hostcomponentdesiredstate";
    String GET_MERGED_TABLE_ROW_COUNT_QUERY = "select count(*) FROM hostcomponentstate hcs "
            + "JOIN hostcomponentdesiredstate hcds ON hcs.service_name=hcds.service_name AND hcs.component_name=hcds.component_name AND hcs.host_id=hcds.host_id";
    int hostComponentStateCount = 0;
    int hostComponentDesiredStateCount = 0;
    int mergedCount = 0;
    ResultSet rs = null;/*from   w  ww. j  a  v  a2  s.  co  m*/
    try {
        Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

        rs = statement.executeQuery(GET_HOST_COMPONENT_STATE_COUNT_QUERY);
        if (rs != null) {
            while (rs.next()) {
                hostComponentStateCount = rs.getInt(1);
            }
        }

        rs = statement.executeQuery(GET_HOST_COMPONENT_DESIRED_STATE_COUNT_QUERY);
        if (rs != null) {
            while (rs.next()) {
                hostComponentDesiredStateCount = rs.getInt(1);
            }
        }

        rs = statement.executeQuery(GET_MERGED_TABLE_ROW_COUNT_QUERY);
        if (rs != null) {
            while (rs.next()) {
                mergedCount = rs.getInt(1);
            }
        }

        if (hostComponentStateCount != hostComponentDesiredStateCount
                || hostComponentStateCount != mergedCount) {
            LOG.error(
                    "Your host component states (hostcomponentstate table) count not equals host component desired states (hostcomponentdesiredstate table) count!");
            errorAvailable = true;
        }

    } catch (SQLException e) {
        LOG.error(
                "Exception occurred during check for same count of host component states and host component desired states: ",
                e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error("Exception occurred during result set closing procedure: ", e);
            }
        }
    }

}

From source file:io.cloudslang.content.database.utils.SQLInputsUtilsTest.java

@Test
public void getResultSetTypeForDbTypeSimple() throws Exception {
    assertEquals(ResultSet.TYPE_FORWARD_ONLY, getResultSetTypeForDbType(TYPE_FORWARD_ONLY, ORACLE_DB_TYPE));
    assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE,
            getResultSetTypeForDbType(TYPE_SCROLL_INSENSITIVE, MYSQL_DB_TYPE));
    assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE,
            getResultSetTypeForDbType(TYPE_SCROLL_SENSITIVE, MSSQL_DB_TYPE));
}

From source file:recite18th.library.Db.java

public static Object getBySql(String sql, String fqn) {
    Object modelInstance = null;//from w w w  .jav  a  2s.c o m
    try {
        Class modelClass = Class.forName(fqn);
        ResultSetMetaData metaData;
        String columnName;
        String fieldValue;
        Field field;

        PreparedStatement pstmt = getCon().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        Logger.getLogger(Db.class.getName()).log(Level.INFO, sql);
        ResultSet resultSet = pstmt.executeQuery();
        metaData = resultSet.getMetaData();
        int nColoumn = metaData.getColumnCount();
        resultSet.beforeFirst();
        Logger.getLogger(Db.class.getName()).log(Level.INFO, "About to process data");
        if (resultSet.next()) {
            Logger.getLogger(Db.class.getName()).log(Level.INFO, "Data exist");
            modelInstance = modelClass.newInstance();
            for (int i = 1; i <= nColoumn; i++) {
                //the good ol'ways.. don't use BeanUtils... The problem is, how can it able to get the 
                //field from super class??
                //field = modelInstance.getClass().getDeclaredField(columnName);
                //field.set(modelInstance, fieldValue);
                columnName = metaData.getColumnName(i);
                fieldValue = resultSet.getString(i);
                PropertyUtils.setSimpleProperty(modelInstance, columnName, fieldValue);
            }
        } else {
            Logger.getLogger(Db.class.getName()).log(Level.INFO, "Data !exist");
        }
    } catch (Exception ex) {
        Logger.getLogger(Db.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
    }
    return modelInstance;
}

From source file:org.dbinterrogator.mssql.MSSQLInstance.java

/**
 * List Views/*from   w ww  . j  a v  a 2 s  .co m*/
 *
 * @param  db  Database Name
 * @return List of tables for selected database
 */
public ArrayList<String> listViews(String db) {
    ArrayList<String> views = new ArrayList();
    try {
        Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        s.executeQuery("SELECT name FROM [" + db + "].sys.views");
        ResultSet rs = s.getResultSet();
        while (rs.next()) {
            views.add(rs.getString(1));
        }
    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }
    if (verbose) {
        System.out.println(views);
    }
    return views;
}