List of usage examples for java.sql ResultSet TYPE_SCROLL_INSENSITIVE
int TYPE_SCROLL_INSENSITIVE
To view the source code for java.sql ResultSet TYPE_SCROLL_INSENSITIVE.
Click Source Link
ResultSet
object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet
. 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:architecture.ee.jdbc.util.impl.JdbcHelperImpl.java
public PreparedStatement createScrollablePreparedStatement(Connection con, String sql) throws SQLException { if (isScrollResultsSupported()) return con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); else/*from w w w . j a va2s . co m*/ return con.prepareStatement(sql); }
From source file:GuestBookServlet.java
private void printComments(PrintWriter out, Locale loc) throws IOException { Connection conn = null;/*from w w w. ja va 2s. com*/ try { DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, loc); ResultSet results; Statement stmt; int rows, count; conn = DriverManager.getConnection(jdbcURL, connectionProperties); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); results = stmt.executeQuery("SELECT NAME, EMAIL, CMT_DATE, " + "COMMENT, COMMENT_ID " + "FROM COMMENT " + "ORDER BY CMT_DATE"); out.println("<dl>"); results.last(); results.next(); rows = results.getRow(); // pick a random row rows = random.nextInt() % rows; if (rows < 4) { // if the random row is less than 4, print the first 4 rows results.afterLast(); } else { // otherwise go to the specified row, print the prior 5 rows results.absolute(rows); } count = 0; // print up to 5 rows going backwards from the randomly // selected row while (results.previous() && (count < 5)) { String name, email, cmt; Date date; count++; name = results.getString(1); if (results.wasNull()) { name = "Unknown User"; } email = results.getString(2); if (results.wasNull()) { email = "user@host"; } date = results.getDate(3); if (results.wasNull()) { date = new Date((new java.util.Date()).getTime()); } cmt = results.getString(4); if (results.wasNull()) { cmt = "No comment."; } out.println("<dt><b>" + name + "</b> (" + email + ") on " + fmt.format(date) + "</dt>"); cmt = noXML(cmt); out.println("<dd> " + cmt + "</dd>"); } out.println("</dl>"); } catch (SQLException e) { out.println("A database error occurred: " + e.getMessage()); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } }
From source file:no.polaric.aprsdb.MyDBSession.java
/** * Get trail poiint for a given station and a given time. *//*from w w w.j a va2 s . co m*/ public Trail.Item getTrailPoint(String src, java.util.Date t) throws java.sql.SQLException { _log.debug("MyDbSession", "getTrailPoint: " + src + ", " + df.format(t)); /* Left outer join with AprsPacket to get path where available */ PreparedStatement stmt = getCon().prepareStatement( " SELECT pr.time, position, speed, course, path, ipath, nopkt FROM \"PosReport\" AS pr" + " LEFT JOIN \"AprsPacket\" AS ap ON pr.src = ap.src AND pr.rtime = ap.time " + " WHERE pr.src=? AND pr.time > ? AND pr.time < ?", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, src); stmt.setTimestamp(2, date2ts(t, -1200)); stmt.setTimestamp(3, date2ts(t, +1200)); ResultSet rs = stmt.executeQuery(); if (rs.first()) { String p = ""; if (rs.getBoolean("nopkt")) p = "(ext)"; else { String path = rs.getString("path"); String ipath = rs.getString("ipath"); if (path == null) p = "?"; else { p = path; if (ipath != null && ipath.length() > 1) p = p + (p.length() > 1 ? "," : "") + ipath; } } return new Trail.Item(rs.getTimestamp("time"), getRef(rs, "position"), rs.getInt("speed"), rs.getInt("course"), p); } else return null; }
From source file:org.xenei.jdbc4sparql.J4SConnection.java
@Override public Statement createStatement() throws SQLException { return createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); }
From source file:de.xwic.sandbox.server.installer.impl.SQLServerDatabaseHandler.java
public boolean renameScope(String oldScope, String newScope) { boolean exist = false; try {/*w ww . j a va 2 s. c o m*/ String sql = "SELECT NAME FROM CRM_SEC_SCOPE WHERE NAME = '" + newScope + "'"; Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); try { if (stmt.execute(sql)) { ResultSet rs = stmt.getResultSet(); if (rs.next()) { exist = true; } } } finally { stmt.close(); } // determine if the newScope does not exist? if (exist) { return false; } stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); sql = "UPDATE CRM_SEC_SCOPE SET NAME = '" + newScope + "' WHERE NAME = '" + oldScope + "'"; try { if (stmt.executeUpdate(sql) != 1) { log.warn("More than one entry with the name " + oldScope + " have been found."); } } finally { stmt.close(); } // now update the SCOPE.propNAME scope types stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); sql = "SELECT NAME FROM CRM_SEC_SCOPE WHERE NAME LIKE '" + oldScope + ".%'"; try { if (stmt.execute(sql)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { String oldName = rs.getString("NAME"); String propertyName = oldName.substring(oldScope.length() + 1); String newName = newScope + "." + propertyName; //rs.updateString("NAME", newName); //rs.updateRow(); Statement stmtUpdate = connection.createStatement(); try { String sqlUpdate = "UPDATE CRM_SEC_SCOPE SET NAME = '" + newName + "' WHERE NAME='" + oldName + "'"; int num = stmtUpdate.executeUpdate(sqlUpdate); if (num == 0) { log.warn("Warning: RENAME FAILED FROM " + oldName + " TO " + newName); } } finally { stmtUpdate.close(); } } } } finally { stmt.close(); } // else, rename the scope + all dependent scopes // that include the property names // oldScopeName + ".%" return true; } catch (Exception e) { // the update process should not be aborted when this happens, so // its just a warning log.warn("Error renaming '" + oldScope + "', into '" + newScope + "'", e); return false; } }
From source file:br.org.indt.ndg.server.client.TemporaryOpenRosaBussinessDelegate.java
private void saveResultsToFilesForDeviceId(String deviceId, String saveDir) { ResultSet resultsSet = null;//from w w w . j a v a2 s . c om PreparedStatement listUsersStmt = null; Connection conn = null; try { conn = getDbConnection(); listUsersStmt = conn.prepareStatement(SELECT_ALL_RESULTS_FOR_USER_STATEMENT, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); listUsersStmt.setString(1, deviceId); resultsSet = listUsersStmt.executeQuery(); try { boolean isValidRow = resultsSet.first(); while (isValidRow) { String resultId = resultsSet.getString(RESULT_ID_COLUMN); String resultContent = resultsSet.getString(RESULT_CONTENT_COLUMN); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(saveDir + resultId + ".xml"); fileOutputStream.write(resultContent.getBytes()); } catch (Exception e) { e.printStackTrace(); } finally { if (fileOutputStream != null) try { fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } isValidRow = resultsSet.next(); } } catch (SQLException ex) { ex.printStackTrace(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { listUsersStmt.close(); conn.close(); } catch (Exception e) { } } }
From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSource.java
/** * Make the SQL request/* w w w. jav a2 s. c om*/ * * @param sql * SQL request * @param maxrows * maximal number of rows * @param fetchSize * fetching size * @return ResultSet * * */ public ResultSet basicQuery(String sql, int maxrows, int fetchSize) { Connection conn = null; ResultSet rs = null; try { conn = getConnection(); PreparedStatement prep = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); if (maxrows > -1) { prep.setMaxRows(maxrows); } if (fetchSize > -1) { prep.setFetchSize(fetchSize); } rs = prep.executeQuery(); return new DBResultSet(rs, prep, conn); } catch (SQLException ex) { LOG.log(Level.SEVERE, null, ex); closeConnection(conn); closeResultSet(rs); conn = null; } catch (RuntimeException ex) { LOG.log(Level.SEVERE, null, ex); closeConnection(conn); closeResultSet(rs); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); closeConnection(conn); closeResultSet(rs); } return null; }
From source file:com.itemanalysis.jmetrik.stats.itemanalysis.ItemAnalysis.java
private void computeDindex(double lowerCut, double upperCut) throws SQLException { //TODO if requested Dindex, begin another loop over database //Compute 27th and 73rd percentile //loop over items and people and compute d indexes. //TODO do this in separate method. Statement stmt = null;/*from w ww.j a v a 2 s. c om*/ ResultSet rs = null; int missingCount = 0; try { //connect to db Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); for (VariableAttributes v : variables) { select.addColumn(sqlTable, v.getName().nameForDatabase()); } stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); Object response = null; RawScore rawScore = null; Double responseScore = null; int[] responseVectorIndex = null; Object[] responseVector = null; ClassicalItem tempItem = null; //loop over examinees while (rs.next()) { //loop over items to compute RawScore rawScore = new RawScore(numberOfItems); missingCount = 0; for (VariableAttributes v : variables) { tempItem = item.get(v.positionInDb()); response = rs.getObject(v.getName().nameForDatabase()); //count missing responses per examinee if (response == null || response.equals("")) {//FIXME need to allow a space " " or other special codes to be viewed as missing data missingCount++; } responseScore = v.getItemScoring().computeItemScore(response); rawScore.increment(responseScore); rawScore.incrementResponseVector(v.positionInDb(), response, responseScore); } //only use complete cases if listwise deletion is specified //otherwise a missing item response is scored as 0 if ((listwiseDeletion && missingCount == 0) || !listwiseDeletion) { //loop over items to compute item analysis responseVector = rawScore.getResponseVector(); responseVectorIndex = rawScore.getResponseVectorIndex(); for (int i = 0; i < responseVector.length; i++) { item.get(responseVectorIndex[i]).incrementDindex(responseVector[i], rawScore.value(), lowerCut, upperCut); } } updateProgress(); } //end loop over examinees } catch (SQLException ex) { throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); conn.setAutoCommit(true); } }
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)); }