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:Main.java

public static void showProperty(ResultSet rset) throws SQLException {
    switch (rset.getType()) {
    case ResultSet.TYPE_FORWARD_ONLY:
        System.out.println("Result set type: TYPE_FORWARD_ONLY");
        break;/*from  w  ww  .ja  v  a  2 s.  c  o m*/
    case ResultSet.TYPE_SCROLL_INSENSITIVE:
        System.out.println("Result set type: TYPE_SCROLL_INSENSITIVE");
        break;
    case ResultSet.TYPE_SCROLL_SENSITIVE:
        System.out.println("Result set type: TYPE_SCROLL_SENSITIVE");
        break;
    default:
        System.out.println("Invalid type");
        break;
    }
    switch (rset.getConcurrency()) {
    case ResultSet.CONCUR_UPDATABLE:
        System.out.println("Result set concurrency: ResultSet.CONCUR_UPDATABLE");
        break;
    case ResultSet.CONCUR_READ_ONLY:
        System.out.println("Result set concurrency: ResultSet.CONCUR_READ_ONLY");
        break;
    default:
        System.out.println("Invalid type");
        break;
    }
    System.out.println("fetch size: " + rset.getFetchSize());
}

From source file:UserPerformance.GetLowerBound.java

public double getLowerB(String GetFixedJobIds) {

    //get mean from db
    double Mean_TimePerItem = 0;
    try {/* ww w .  ja  va  2s .  c o m*/
        ResultSet reset;
        Statement stmt;
        String query;

        query = "SELECT AVG(TIME_PER_ONE_ITEM)\n" + "  FROM dbo.UsersVsCompleteItems\n"
                + "  WHERE JobFinished_FIXED_JOB_ID = '" + GetFixedJobIds + "'";

        stmt = ConnectSql.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        reset = stmt.executeQuery(query);

        if (reset.next()) {
            String wd = reset.getString(1);
            Mean_TimePerItem = Double.parseDouble(wd);
        }

        reset.close();
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        JOptionPane.showMessageDialog(null, "Please contact for support.");
    }

    //get item Count from db
    double n_Count = 0;
    try {
        ResultSet reset;
        Statement stmt;
        String query;

        query = "SELECT COUNT(TIME_PER_ONE_ITEM)\n" + "  FROM dbo.UsersVsCompleteItems\n"
                + "  WHERE JobFinished_FIXED_JOB_ID = '" + GetFixedJobIds + "'";

        stmt = ConnectSql.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        reset = stmt.executeQuery(query);

        if (reset.next()) {
            String wd = reset.getString(1);
            n_Count = Double.parseDouble(wd);
        }

        reset.close();
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        JOptionPane.showMessageDialog(null, "Please contact for support.");
    }

    //get item Standed deviation from db
    double st_Dev = 0;
    try {
        ResultSet reset;
        Statement stmt;
        String query;

        query = "SELECT STDEV(TIME_PER_ONE_ITEM)\n" + "  FROM dbo.UsersVsCompleteItems\n"
                + "  WHERE JobFinished_FIXED_JOB_ID = '" + GetFixedJobIds + "'";

        stmt = ConnectSql.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        reset = stmt.executeQuery(query);

        if (reset.next()) {
            st_Dev = reset.getDouble(1);
        }

        reset.close();
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        JOptionPane.showMessageDialog(null, "Please contact for support.");
    }

    //get alfa
    Double alfa = 0.9;
    System.out.println("Confidence Interval for Fixed Job : " + alfa * 100 + "%");

    // Calculate 90% confidence interval
    double S_Mean_TimePerItem = roundTwoDecimals(Mean_TimePerItem);

    double ci = calcMeanCI(n_Count, st_Dev, alfa);
    System.out.println("Mean for Fixed Job : " + S_Mean_TimePerItem);

    double S_lower = (Mean_TimePerItem - ci);
    double lower = roundTwoDecimals(S_lower);

    double S_upper = (Mean_TimePerItem + ci);
    double upper = roundTwoDecimals(S_upper);

    System.out.println("lower Limit for Fixed Job : " + lower);
    return lower;
}

From source file:com.adaptris.jdbc.JdbcResultSetImpl.java

@Override
public Iterable<JdbcResultRow> getRows() {
    return new Iterable<JdbcResultRow>() {

        @Override//from  ww w  .  ja  v  a2 s . c  o  m
        public Iterator<JdbcResultRow> iterator() {
            try {
                switch (resultSet.getType()) {
                case ResultSet.TYPE_FORWARD_ONLY:
                    return new ForwardOnlyResultSetIterator(resultSet);

                case ResultSet.TYPE_SCROLL_SENSITIVE:
                case ResultSet.TYPE_SCROLL_INSENSITIVE:
                    return new ScrollableResultSetIterator(resultSet);

                default:
                    throw new RuntimeException("ResultSet was of unknown type");
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    };
}

From source file:org.biblionum.commentaire.modele.CommentaireOuvragesModele.java

public static boolean updateOuvragetype(DataSource ds, int keyId, String contenu_commentaire,
        String date_commentaire, int utilisateurid, int ouvrageid) throws SQLException {

    Connection con = ds.getConnection();
    String sql = "SELECT * FROM ouvragetype WHERE id = ?";
    PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_UPDATABLE);
    statement.setInt(1, keyId);//from ww w .j av a 2 s.co  m
    ResultSet entry = statement.executeQuery();

    entry.last();
    int rows = entry.getRow();
    entry.beforeFirst();
    if (rows == 0) {
        entry.close();
        statement.close();
        con.close();
        return false;
    }
    entry.next();

    if (contenu_commentaire != null) {
        entry.updateString("contenu_commentaire", contenu_commentaire);
    }
    if (date_commentaire != null) {
        entry.updateString("date_commentaire", date_commentaire);
    }
    entry.updateInt("utilisateurid", utilisateurid);
    entry.updateInt("ouvrageid", ouvrageid);

    entry.updateRow();
    entry.close();
    statement.close();
    con.close();
    return true;
}

From source file:RetrieveMusicFiles.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  ww.  j ava  2s.  com
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    String android_id = request.getParameter("androidId");

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {

        Class.forName(JDBC_DRIVER);
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        String sql = "select a.album_title, a.album_artist, a.album_composer, a.release_year, "
                + "s.song_title, s.genre, s.artist_name from album a, song s, user_music_data u "
                + "where u.android_id='" + android_id + "' and u.song_id=s.song_id and s.album_id=a.album_id";
        rs = stmt.executeQuery(sql);
        JSONObject json = new JSONObject();
        JSONArray jArray = new JSONArray();
        while (rs.next()) {
            JSONObject element = new JSONObject();
            element.put("title", rs.getString("s.song_title"));
            element.put("album", rs.getString("a.album_title"));
            element.put("artist", rs.getString("s.artist_name"));
            element.put("genre", rs.getString("s.genre"));
            element.put("album_artist", rs.getString("a.album_artist"));
            element.put("album_composer", rs.getString("a.album_composer"));
            element.put("album_year", rs.getString("a.release_year"));

            jArray.put(element);
        }
        json.put("data", jArray);
        out.print(json);
        //out.print(resultJSON);
    } catch (Exception se) {
        //out.println("Exception preparing or processing query: " + se);
        se.printStackTrace();
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {

        }
    }
}

From source file:org.biblionum.ouvrage.modele.CategorieOuvrageModele.java

/**
 * Java method that updates a row in the generated sql table
 *
 * @param con (open java.sql.Connection)
 * @param designation_categorie//from  w w  w . java2s.  c  om
 * @return boolean (true on success)
 * @throws SQLException
 */
public static boolean updateCategorieouvrage(DataSource ds, int keyId, String designation_categorie)
        throws SQLException {
    con = ds.getConnection();
    String sql = "SELECT * FROM categorieouvrage WHERE id = ?";
    PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_UPDATABLE);
    statement.setInt(1, keyId);
    ResultSet entry = statement.executeQuery();

    entry.last();
    int rows = entry.getRow();
    entry.beforeFirst();
    if (rows == 0) {
        entry.close();
        statement.close();
        con.close();
        return false;
    }
    entry.next();

    if (designation_categorie != null) {
        entry.updateString("designation_categorie", designation_categorie);
    }

    entry.updateRow();
    entry.close();
    statement.close();
    con.close();
    return true;
}

From source file:org.syncope.core.init.ContentLoader.java

@Transactional
public void load() {
    // 0. DB connection, to be used below
    Connection conn = DataSourceUtils.getConnection(dataSource);

    // 1. Check wether we are allowed to load default content into the DB
    Statement statement = null;/*w ww .j  av  a2  s. com*/
    ResultSet resultSet = null;
    boolean existingData = false;
    try {
        statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        resultSet = statement.executeQuery("SELECT * FROM " + SyncopeConf.class.getSimpleName());
        resultSet.last();

        existingData = resultSet.getRow() > 0;
    } catch (SQLException e) {
        LOG.error("Could not access to table " + SyncopeConf.class.getSimpleName(), e);

        // Setting this to true make nothing to be done below
        existingData = true;
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            LOG.error("While closing SQL result set", e);
        }
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            LOG.error("While closing SQL statement", e);
        }
    }

    if (existingData) {
        LOG.info("Data found in the database, leaving untouched");
        return;
    }

    LOG.info("Empty database found, loading default content");

    // 2. Create views
    LOG.debug("Creating views");
    try {
        InputStream viewsStream = getClass().getResourceAsStream("/views.xml");
        Properties views = new Properties();
        views.loadFromXML(viewsStream);

        for (String idx : views.stringPropertyNames()) {
            LOG.debug("Creating view {}", views.get(idx).toString());

            try {
                statement = conn.createStatement();
                statement.executeUpdate(views.get(idx).toString().replaceAll("\\n", " "));
                statement.close();
            } catch (SQLException e) {
                LOG.error("Could not create view ", e);
            }
        }

        LOG.debug("Views created, go for indexes");
    } catch (Throwable t) {
        LOG.error("While creating views", t);
    }

    // 3. Create indexes
    LOG.debug("Creating indexes");
    try {
        InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml");
        Properties indexes = new Properties();
        indexes.loadFromXML(indexesStream);

        for (String idx : indexes.stringPropertyNames()) {
            LOG.debug("Creating index {}", indexes.get(idx).toString());

            try {
                statement = conn.createStatement();
                statement.executeUpdate(indexes.get(idx).toString());
                statement.close();
            } catch (SQLException e) {
                LOG.error("Could not create index ", e);
            }
        }

        LOG.debug("Indexes created, go for default content");
    } catch (Throwable t) {
        LOG.error("While creating indexes", t);
    } finally {
        DataSourceUtils.releaseConnection(conn, dataSource);
    }

    try {
        conn.close();
    } catch (SQLException e) {
        LOG.error("While closing SQL connection", e);
    }

    // 4. Load default content
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        parser.parse(getClass().getResourceAsStream("/content.xml"), importExport);
        LOG.debug("Default content successfully loaded");
    } catch (Throwable t) {
        LOG.error("While loading default content", t);
    }
}

From source file:org.biblionum.ouvrage.modele.OuvrageTypeModele.java

/**
 * Java method that updates a row in the generated sql table
 *
 * @param con (open java.sql.Connection)
 * @param designation_typeou/*w ww  .j a  v  a2s  .  com*/
 * @return boolean (true on success)
 * @throws SQLException
 */
public boolean updateOuvragetype(DataSource ds, int keyId, String designation_typeou) throws SQLException {
    con = ds.getConnection();
    String sql = "SELECT * FROM ouvragetype WHERE id = ?";
    PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_UPDATABLE);
    statement.setInt(1, keyId);
    ResultSet entry = statement.executeQuery();

    entry.last();
    int rows = entry.getRow();
    entry.beforeFirst();
    if (rows == 0) {
        entry.close();
        statement.close();
        con.close();
        return false;
    }
    entry.next();

    if (designation_typeou != null) {
        entry.updateString("designation_typeou", designation_typeou);
    }

    entry.updateRow();
    entry.close();
    statement.close();
    con.close();
    return true;
}

From source file:net.pms.database.TableThumbnails.java

/**
 * Attempts to find a thumbnail in this table by MD5 hash. If not found,
 * it writes the new thumbnail to this table.
 * Finally, it writes the ID from this table as the THUMBID in the FILES
 * table.//from   w ww .j  ava2s  . c  o m
 *
 * @param thumbnail
 * @param fullPathToFile
 */
public static void setThumbnail(final DLNAThumbnail thumbnail, final String fullPathToFile) {
    String query;
    String md5Hash = DigestUtils.md5Hex(thumbnail.getBytes(false));
    try (Connection connection = database.getConnection()) {
        query = "SELECT * FROM " + TABLE_NAME + " WHERE MD5 = " + sqlQuote(md5Hash) + " LIMIT 1";
        LOGGER.trace("Searching for thumbnail in {} with \"{}\" before update", TABLE_NAME, query);

        TABLE_LOCK.writeLock().lock();
        try (PreparedStatement statement = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE, Statement.RETURN_GENERATED_KEYS)) {
            connection.setAutoCommit(false);
            try (ResultSet result = statement.executeQuery()) {
                if (result.next()) {
                    LOGGER.trace(
                            "Found existing file entry with ID {} in {}, setting the THUMBID in the FILES table",
                            result.getInt("ID"), TABLE_NAME);

                    // Write the existing thumbnail ID to the FILES table
                    PMS.get().getDatabase().updateThumbnailId(fullPathToFile, result.getInt("ID"));
                } else {
                    LOGGER.trace("File entry \"{}\" not found in {}", md5Hash, TABLE_NAME);
                    result.moveToInsertRow();
                    result.updateString("MD5", md5Hash);
                    result.updateObject("THUMBNAIL", thumbnail);
                    result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis()));
                    result.insertRow();

                    try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
                        if (generatedKeys.next()) {
                            // Write the new thumbnail ID to the FILES table
                            LOGGER.trace(
                                    "Inserting new thumbnail with ID {}, setting the THUMBID in the FILES table",
                                    generatedKeys.getInt(1));
                            PMS.get().getDatabase().updateThumbnailId(fullPathToFile, generatedKeys.getInt(1));
                        }
                    }
                }
            } finally {
                connection.commit();
            }
        } finally {
            TABLE_LOCK.writeLock().unlock();
        }
    } catch (SQLException e) {
        LOGGER.error("Database error while writing \"{}\" to {}: {}", md5Hash, TABLE_NAME, e.getMessage());
        LOGGER.trace("", e);
    }
}

From source file:org.biblionum.authentification.modele.UtilisateurModele.java

/**
 * Java method that updates a row in the generated sql table
 *
 * @param con (open java.sql.Connection)
 * @param nom/*  w ww  .  jav  a 2  s.co  m*/
 * @param password
 * @param pseudo
 * @param prenom
 * @param utilisateur_type_id
 * @return boolean (true on success)
 * @throws SQLException
 */
public boolean updateUtilisateur(DataSource ds, int keyId, String nom, String password, String pseudo,
        String prenom) throws SQLException {
    con = ds.getConnection();
    String sql = "SELECT * FROM utilisateur WHERE id = ?";
    PreparedStatement statement = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_UPDATABLE);
    statement.setInt(1, keyId);
    ResultSet entry = statement.executeQuery();

    entry.last();
    int rows = entry.getRow();
    entry.beforeFirst();
    if (rows == 0) {
        entry.close();
        statement.close();
        con.close();
        return false;
    }
    entry.next();

    if (nom != null) {
        entry.updateString("nom", nom);
    }
    if (password != null) {
        entry.updateString("password", password);
    }
    if (pseudo != null) {
        entry.updateString("pseudo", pseudo);
    }
    if (prenom != null) {
        entry.updateString("prenom", prenom);
    }

    entry.updateRow();
    entry.close();
    statement.close();
    con.close();
    return true;
}