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:com.itemanalysis.jmetrik.stats.frequency.FrequencyAnalysis.java
public void summarize() throws SQLException { Statement stmt = null;/*from w ww . java 2s.c o m*/ ResultSet rs = null; frequencyTables = new LinkedHashMap<VariableAttributes, Frequency>(); Frequency temp = null; 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()); String strValue = ""; double dblValue = 0; while (rs.next()) { for (VariableAttributes v : variables) { temp = frequencyTables.get(v); if (temp == null) { temp = new Frequency(); frequencyTables.put(v, temp); } if (v.getType().getDataType() == DataType.STRING) { strValue = rs.getString(v.getName().nameForDatabase()); if (!rs.wasNull() && !"".equals(strValue)) { temp.addValue(strValue); } } else { dblValue = rs.getDouble(v.getName().nameForDatabase()); if (!rs.wasNull()) { temp.addValue(dblValue); } } } updateProgress(); } rs.close(); stmt.close(); for (VariableAttributes v : frequencyTables.keySet()) { publishTable(v); } }
From source file:com.taobao.datax.plugins.writer.mysqlwriter.MysqlWriter.java
@Override public int prepare(PluginParam param) { this.setParam(param); DBSource.register(this.sourceUniqKey, this.genProperties()); if (StringUtils.isBlank(this.pre)) return PluginStatus.SUCCESS.value(); Statement stmt = null;// www . j av a 2s .co m try { this.connection = DBSource.getConnection(this.sourceUniqKey); stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); for (String subSql : this.pre.split(";")) { this.logger.info(String.format("Excute prepare sql %s .", subSql)); stmt.execute(subSql); } return PluginStatus.SUCCESS.value(); } catch (Exception e) { throw new DataExchangeException(e.getCause()); } finally { try { if (null != stmt) { stmt.close(); } if (null != this.connection) { this.connection.close(); this.connection = null; } } catch (SQLException e) { } } }
From source file:edu.ku.brc.specify.conversion.IdHashMapper.java
/** * @param tblName// w w w .ja v a 2 s .c om * @return */ public int getMapCount(final String tblName) { Statement cntStmt = null; ResultSet rs = null; try { Integer count = 0; cntStmt = oldConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = cntStmt.executeQuery("select count(*) from " + tblName); if (rs.first()) { count = rs.getInt(1); if (count == null) { return 0; } } return count; } catch (SQLException ex) { } finally { try { if (rs != null) rs.close(); if (cntStmt != null) cntStmt.close(); } catch (Exception ex) { } } return 0; }
From source file:org.acmsl.queryj.tools.handlers.DatabaseMetaDataLoggingHandler.java
/** * Handles given information./*from w w w . j ava 2 s. c o m*/ * @param metaData the database metadata. * @return <code>true</code> if the chain should be stopped. * @throws QueryJBuildException if the metadata cannot be logged. */ protected boolean handle(@NotNull final DatabaseMetaData metaData) throws QueryJBuildException { final boolean result = false; @Nullable Log t_Log = null; try { t_Log = UniqueLogFactory.getLog(DatabaseMetaDataLoggingHandler.class); if (t_Log != null) { t_Log.debug("Numeric functions:" + metaData.getNumericFunctions()); t_Log.debug("String functions:" + metaData.getStringFunctions()); t_Log.debug("System functions:" + metaData.getSystemFunctions()); t_Log.debug("Time functions:" + metaData.getTimeDateFunctions()); t_Log.debug("insertsAreDetected(TYPE_FORWARD_ONLY):" + metaData.insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("insertsAreDetected(TYPE_SCROLL_INSENSITIVE):" + metaData.insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("insertsAreDetected(TYPE_SCROLL_SENS):" + metaData.insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("isCatalogAtStart():" + metaData.isCatalogAtStart()); t_Log.debug("isReadOnly():" + metaData.isReadOnly()); /* * Fails for MySQL with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.locatorsUpdateCopy() t_Log.debug( "locatorsUpdateCopy():" + metaData.locatorsUpdateCopy()); */ t_Log.debug("nullPlusNonNullIsNull():" + metaData.nullPlusNonNullIsNull()); t_Log.debug("nullsAreSortedAtEnd():" + metaData.nullsAreSortedAtEnd()); t_Log.debug("nullsAreSortedAtStart():" + metaData.nullsAreSortedAtStart()); t_Log.debug("nullsAreSortedHigh():" + metaData.nullsAreSortedHigh()); t_Log.debug("nullsAreSortedLow():" + metaData.nullsAreSortedLow()); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("storesLowerCaseIdentifiers():" + metaData.storesLowerCaseIdentifiers()); t_Log.debug("storesLowerCaseQuotedIdentifiers():" + metaData.storesLowerCaseQuotedIdentifiers()); t_Log.debug("storesMixedCaseIdentifiers():" + metaData.storesMixedCaseIdentifiers()); t_Log.debug("storesMixedCaseQuotedIdentifiers():" + metaData.storesMixedCaseQuotedIdentifiers()); t_Log.debug("storesUpperCaseIdentifiers():" + metaData.storesUpperCaseIdentifiers()); t_Log.debug("storesUpperCaseQuotedIdentifiers():" + metaData.storesUpperCaseQuotedIdentifiers()); t_Log.debug("supportsAlterTableWithAddColumn():" + metaData.supportsAlterTableWithAddColumn()); t_Log.debug("supportsAlterTableWithDropColumn():" + metaData.supportsAlterTableWithDropColumn()); t_Log.debug("supportsANSI92EntryLevelSQL():" + metaData.supportsANSI92EntryLevelSQL()); t_Log.debug("supportsANSI92FullSQL():" + metaData.supportsANSI92FullSQL()); t_Log.debug("supportsANSI92IntermediateSQL():" + metaData.supportsANSI92IntermediateSQL()); t_Log.debug("supportsBatchUpdates():" + metaData.supportsBatchUpdates()); t_Log.debug( "supportsCatalogsInDataManipulation():" + metaData.supportsCatalogsInDataManipulation()); t_Log.debug( "supportsCatalogsInIndexDefinitions():" + metaData.supportsCatalogsInIndexDefinitions()); t_Log.debug("supportsCatalogsInPrivilegeDefinitions():" + metaData.supportsCatalogsInPrivilegeDefinitions()); t_Log.debug("supportsCatalogsInProcedureCalls():" + metaData.supportsCatalogsInProcedureCalls()); t_Log.debug( "supportsCatalogsInTableDefinitions():" + metaData.supportsCatalogsInTableDefinitions()); t_Log.debug("supportsColumnAliasing():" + metaData.supportsColumnAliasing()); t_Log.debug("supportsConvert():" + metaData.supportsConvert()); t_Log.debug("supportsCoreSQLGrammar():" + metaData.supportsCoreSQLGrammar()); t_Log.debug("supportsCorrelatedSubqueries():" + metaData.supportsCorrelatedSubqueries()); t_Log.debug("supportsDataDefinitionAndDataManipulationTransactions():" + metaData.supportsDataDefinitionAndDataManipulationTransactions()); t_Log.debug("supportsDataManipulationTransactionsOnly():" + metaData.supportsDataManipulationTransactionsOnly()); t_Log.debug("supportsDifferentTableCorrelationNames():" + metaData.supportsDifferentTableCorrelationNames()); t_Log.debug("supportsExpressionsInOrderBy():" + metaData.supportsExpressionsInOrderBy()); t_Log.debug("supportsExtendedSQLGrammar():" + metaData.supportsExtendedSQLGrammar()); t_Log.debug("supportsFullOuterJoins():" + metaData.supportsFullOuterJoins()); String t_strSupportsGetGeneratedKeys = Boolean.FALSE.toString(); try { t_strSupportsGetGeneratedKeys = "" + metaData.supportsGetGeneratedKeys(); } catch (@NotNull final SQLException sqlException) { t_strSupportsGetGeneratedKeys += sqlException.getMessage(); } t_Log.debug("supportsGetGeneratedKeys():" + t_strSupportsGetGeneratedKeys); t_Log.debug("supportsGroupBy():" + metaData.supportsGroupBy()); t_Log.debug("supportsGroupByBeyondSelect():" + metaData.supportsGroupByBeyondSelect()); t_Log.debug("supportsGroupByUnrelated():" + metaData.supportsGroupByUnrelated()); t_Log.debug("supportsIntegrityEnhancementFacility():" + metaData.supportsIntegrityEnhancementFacility()); t_Log.debug("supportsLikeEscapeClause():" + metaData.supportsLikeEscapeClause()); t_Log.debug("supportsLimitedOuterJoins():" + metaData.supportsLimitedOuterJoins()); t_Log.debug("supportsMinimumSQLGrammar():" + metaData.supportsMinimumSQLGrammar()); t_Log.debug("supportsMixedCaseIdentifiers():" + metaData.supportsMixedCaseIdentifiers()); t_Log.debug( "supportsMixedCaseQuotedIdentifiers():" + metaData.supportsMixedCaseQuotedIdentifiers()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsMultipleOpenResults() t_Log.debug( "supportsMultipleOpenResults():" + metaData.supportsMultipleOpenResults()); */ t_Log.debug("supportsMultipleResultSets():" + metaData.supportsMultipleResultSets()); t_Log.debug("supportsMultipleTransactions():" + metaData.supportsMultipleTransactions()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsNamedParameters() t_Log.debug( "supportsNamedParameters():" + metaData.supportsNamedParameters()); */ t_Log.debug("supportsNonNullableColumns():" + metaData.supportsNonNullableColumns()); t_Log.debug("supportsOpenCursorsAcrossCommit():" + metaData.supportsOpenCursorsAcrossCommit()); t_Log.debug("supportsOpenCursorsAcrossRollback():" + metaData.supportsOpenCursorsAcrossRollback()); t_Log.debug( "supportsOpenStatementsAcrossCommit():" + metaData.supportsOpenStatementsAcrossCommit()); t_Log.debug("supportsOpenStatementsAcrossRollback():" + metaData.supportsOpenStatementsAcrossRollback()); t_Log.debug("supportsOrderByUnrelated():" + metaData.supportsOrderByUnrelated()); t_Log.debug("supportsOuterJoins():" + metaData.supportsOuterJoins()); t_Log.debug("supportsPositionedDelete():" + metaData.supportsPositionedDelete()); t_Log.debug("supportsPositionedUpdate():" + metaData.supportsPositionedUpdate()); t_Log.debug("supportsResultSetConcurrency(TYPE_FORWARD_ONLY,CONCUR_READ_ONLY):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_FORWARD_ONLY,CONCUR_UPDATABLE):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY):" + metaData.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_INSENSITIVE,CONCUR_UPDATABLE):" + metaData.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_SENSITIVE,CONCUR_READ_ONLY):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_SENSITIVE,CONCUR_UPDATABLE):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsResultSetHoldability() t_Log.debug( "supportsResultSetHoldability(" + "HOLD_CURSORS_OVER_COMMIT):" + metaData.supportsResultSetHoldability( ResultSet.HOLD_CURSORS_OVER_COMMIT)); t_Log.debug( "supportsResultSetHoldability(" + "CLOSE_CURSORS_AT_COMMIT):" + metaData.supportsResultSetHoldability( ResultSet.CLOSE_CURSORS_AT_COMMIT)); */ t_Log.debug("supportsResultSetType(TYPE_FORWARD_ONLY):" + metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("supportsResultSetType(TYPE_SCROLL_SENSITIVE):" + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsSavePoints() t_Log.debug( "supportsSavepoints():" + metaData.supportsSavepoints()); */ t_Log.debug("supportsSchemasInDataManipulation():" + metaData.supportsSchemasInDataManipulation()); t_Log.debug("supportsSchemasInIndexDefinitions():" + metaData.supportsSchemasInIndexDefinitions()); t_Log.debug("supportsSchemasInPrivilegeDefinitions():" + metaData.supportsSchemasInPrivilegeDefinitions()); t_Log.debug("supportsSchemasInProcedureCalls():" + metaData.supportsSchemasInProcedureCalls()); t_Log.debug("supportsSchemasInTableDefinitions():" + metaData.supportsSchemasInTableDefinitions()); t_Log.debug("supportsSelectForUpdate():" + metaData.supportsSelectForUpdate()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsStatementPooling() t_Log.debug( "supportsStatementPooling():" + metaData.supportsStatementPooling()); */ t_Log.debug("supportsStoredProcedures():" + metaData.supportsStoredProcedures()); t_Log.debug("supportsSubqueriesInComparisons():" + metaData.supportsSubqueriesInComparisons()); t_Log.debug("supportsSubqueriesInExists():" + metaData.supportsSubqueriesInExists()); t_Log.debug("supportsSubqueriesInIns():" + metaData.supportsSubqueriesInIns()); t_Log.debug("supportsSubqueriesInQuantifieds():" + metaData.supportsSubqueriesInQuantifieds()); t_Log.debug("supportsTableCorrelationNames():" + metaData.supportsTableCorrelationNames()); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_NONE):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)); t_Log.debug("supportsTransactions():" + metaData.supportsTransactions()); t_Log.debug("supportsUnion():" + metaData.supportsUnion()); t_Log.debug("supportsUnionAll():" + metaData.supportsUnionAll()); t_Log.debug("updatesAreDetected(TYPE_FORWARD_ONLY):" + metaData.updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("updatesAreDetected(TYPE_SCROLL_INSENSITIVE):" + metaData.updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("updatesAreDetected(" + "TYPE_SCROLL_SENS):" + metaData.updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("usesLocalFilePerTable():" + metaData.usesLocalFilePerTable()); t_Log.debug("usesLocalFiles():" + metaData.usesLocalFiles()); } } catch (@NotNull final SQLException sqlException) { t_Log.error("Database metadata request failed.", sqlException); } return result; }
From source file:nl.b3p.viewer.ViewerIntegrationTest.java
/** * test if the database has the right metadata version. * * @throws SQLException if something goes wrong executing the query * @throws ClassNotFoundException if the postgres driver cannot be found. *///from ww w. j av a 2 s . c o m @Test public void testMetadataVersion() throws SQLException, ClassNotFoundException { // get 'database_version' from table metadata and check that is has the value of 'n' Connection connection = DriverManager.getConnection(databaseprop.getProperty("testdb.url"), databaseprop.getProperty("testdb.username"), databaseprop.getProperty("testdb.password")); ResultSet rs = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY) .executeQuery("SELECT config_value FROM metadata WHERE config_key = 'database_version'"); String actual_config_value = "-1"; while (rs.next()) { actual_config_value = rs.getString("config_value"); } assertThat("There is only one 'database_version' record (first and last should be same record).", rs.isLast(), equalTo(rs.isFirst())); rs.close(); connection.close(); assertEquals("The database version should be the same.", DatabaseSynchronizer.getUpdateNumber(), actual_config_value); }
From source file:com.taobao.datax.plugins.writer.oraclejdbcwriter.OracleJdbcWriter.java
@Override public int prepare(PluginParam param) { this.setParam(param); DBSource.register(this.sourceUniqKey, this.genProperties()); if (StringUtils.isBlank(this.pre)) return PluginStatus.SUCCESS.value(); Statement stmt = null;/*www . j a v a 2s. c o m*/ try { this.connection = DBSource.getConnection(this.sourceUniqKey); stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); for (String subSql : this.pre.split(";")) { this.logger.info(String.format("Excute prepare sql %s .", subSql)); stmt.execute(subSql); } this.connection.commit(); return PluginStatus.SUCCESS.value(); } catch (Exception e) { throw new DataExchangeException(e.getCause()); } finally { try { if (null != stmt) { stmt.close(); } if (null != this.connection) { this.connection.close(); this.connection = null; } } catch (SQLException e) { } } }
From source file:org.etudes.jforum.dao.sqlserver.SqlServerPostDAO.java
/** * @see org.etudes.jforum.dao.PostDAO#selectAllByTopicByLimit(int, int, int) *//*from ww w. ja va 2 s .co m*/ public List selectAllByTopicByLimit(int topicId, int startFrom, int count) throws Exception { List l = new ArrayList(); String top = SystemGlobals.getSql("GenericModel.selectByLimit"); PreparedStatement p = JForum.getConnection().prepareStatement( top + " " + count + " " + SystemGlobals.getSql("PostModel.selectAllByTopicByLimit1") + " " + top + " " + startFrom + " " + SystemGlobals.getSql("PostModel.selectAllByTopicByLimit2"), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); if (logger.isDebugEnabled()) logger.debug(top + " " + count + " " + SystemGlobals.getSql("PostModel.selectAllByTopicByLimit1") + " " + top + " " + startFrom + " " + SystemGlobals.getSql("PostModel.selectAllByTopicByLimit2")); p.setInt(1, topicId); p.setInt(2, topicId); ResultSet rs = p.executeQuery(); while (rs.next()) { l.add(this.makePost(rs)); } rs.close(); p.close(); return l; }
From source file:com.itemanalysis.jmetrik.graph.density.DensityAnalysis.java
public XYSeriesCollection summarize() throws SQLException, IllegalArgumentException { Statement stmt = null;/* w w w.j a va 2 s . c o m*/ ResultSet rs = null; TreeMap<String, ResizableDoubleArray> data = new TreeMap<String, ResizableDoubleArray>(); //set progress bar information int nrow = 0; JmetrikPreferencesManager pref = new JmetrikPreferencesManager(); String dbType = pref.getDatabaseType(); if (DatabaseType.APACHE_DERBY.toString().equals(dbType)) { JmetrikDatabaseFactory dbFactory = new JmetrikDatabaseFactory(DatabaseType.APACHE_DERBY); nrow = dao.getRowCount(conn, tableName); } else { //add other databases here when functionality is added } maxProgress = (double) nrow; Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, variable.getName().nameForDatabase()); if (hasGroupingVariable) select.addColumn(sqlTable, groupVar.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); String conditionalName = ""; ResizableDoubleArray cData = null; double value = Double.NaN; while (rs.next()) { if (groupVar != null) { String groupName = rs.getString(groupVar.getName().nameForDatabase()); if (rs.wasNull()) { groupName = ""; } conditionalName = groupName; } else { conditionalName = "Series 1"; } cData = data.get(conditionalName); if (cData == null) { cData = new ResizableDoubleArray((int) maxProgress); data.put(conditionalName, cData); } value = rs.getDouble(variable.getName().nameForDatabase()); if (!rs.wasNull()) { cData.addElement(value); } updateProgress(); } rs.close(); stmt.close(); String kType = command.getSelectOneOption("kernel").getSelectedArgument(); double adjustment = command.getFreeOption("adjust").getDouble(); KernelFactory kernelFactory = new KernelFactory(kType); KernelFunction kernelFunction = kernelFactory.getKernelFunction(); Bandwidth bandwidth = null; KernelDensity density = null; UniformDistributionApproximation uniform = null; Min min = new Min(); Max max = new Max(); double[] x = null; this.firePropertyChange("progress-ind-on", null, null); XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYSeries series = null; for (String s : data.keySet()) { series = new XYSeries(s); x = data.get(s).getElements(); bandwidth = new ScottsBandwidth(x, adjustment); uniform = new UniformDistributionApproximation(min.evaluate(x), max.evaluate(x), KERNEL_POINTS); density = new KernelDensity(kernelFunction, bandwidth, uniform); double[] dens = density.evaluate(x); double[] points = density.getPoints(); for (int i = 0; i < dens.length; i++) { series.add(points[i], dens[i]); } seriesCollection.addSeries(series); } return seriesCollection; }
From source file:recite18th.library.Db.java
public static ResultSet selectQuery(String sql) { try {/* w w w .ja va 2 s. co m*/ sql = sql.toUpperCase(); Statement stmt = getCon().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = stmt.executeQuery(sql); return resultSet; } catch (SQLException ex) { Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.itemanalysis.jmetrik.stats.ranking.RankingAnalysis.java
private ResizableDoubleArray getData() throws SQLException { Statement stmt = null;// w w w . ja v a 2 s . co m ResultSet rs = null; ResizableDoubleArray data = new ResizableDoubleArray((int) (maxProgress / 2.0)); try { //connect to table to create data set to be ranked Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, variable.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); String vNameDb = variable.getName().nameForDatabase(); double x = Double.NaN; int dbIndex = 0;//row position index for all records in db while (rs.next()) { x = rs.getDouble(vNameDb); if (!rs.wasNull()) { if (ascending) { data.addElement(x);//ascending order } else { data.addElement(-x);//descending order } } else { missingIndex.add(dbIndex); } dbIndex++; updateProgress(); } return data; } catch (SQLException ex) { throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } }