List of usage examples for java.sql ResultSet CONCUR_UPDATABLE
int CONCUR_UPDATABLE
To view the source code for java.sql ResultSet CONCUR_UPDATABLE.
Click Source Link
ResultSet
object that may be updated. From source file:gov.nih.nci.migration.MigrationDriver.java
private void encryptDecryptUserInformation() throws EncryptionException, SQLException { Connection connection = getConnection(); //Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); connection.setAutoCommit(false);//from ww w . j a va 2s.com ResultSet resultSet = null; if ("oracle".equals(DATABASE_TYPE)) { //resultSet = stmt.executeQuery("SELECT CSM_USER.* FROM CSM_USER FOR UPDATE"); resultSet = stmt.executeQuery("SELECT CSM_USER.* FROM CSM_USER"); } else { resultSet = stmt.executeQuery("SELECT * FROM CSM_USER"); } String userPassword = null; String firstName = null; String lastName = null; String organization = null; String department = null; String title = null; String phoneNumber = null; String emailId = null; String encryptedUserPassword = null; Date expiryDate = null; while (resultSet.next()) { userPassword = resultSet.getString("PASSWORD"); firstName = resultSet.getString("FIRST_NAME"); lastName = resultSet.getString("LAST_NAME"); organization = resultSet.getString("ORGANIZATION"); department = resultSet.getString("DEPARTMENT"); title = resultSet.getString("TITLE"); phoneNumber = resultSet.getString("PHONE_NUMBER"); emailId = resultSet.getString("EMAIL_ID"); if (!StringUtilities.isBlank(userPassword)) { String orgPasswordStr = desEncryption.decrypt(userPassword); encryptedUserPassword = aesEncryption.encrypt(orgPasswordStr); if (!StringUtilities.isBlank(encryptedUserPassword)) { resultSet.updateString("PASSWORD", encryptedUserPassword); } } if (!StringUtilities.isBlank(firstName)) resultSet.updateString("FIRST_NAME", aesEncryption.encrypt(firstName)); if (!StringUtilities.isBlank(lastName)) resultSet.updateString("LAST_NAME", aesEncryption.encrypt(lastName)); if (!StringUtilities.isBlank(organization)) resultSet.updateString("ORGANIZATION", aesEncryption.encrypt(organization)); if (!StringUtilities.isBlank(department)) resultSet.updateString("DEPARTMENT", aesEncryption.encrypt(department)); if (!StringUtilities.isBlank(title)) resultSet.updateString("TITLE", aesEncryption.encrypt(title)); if (!StringUtilities.isBlank(phoneNumber)) resultSet.updateString("PHONE_NUMBER", aesEncryption.encrypt(phoneNumber)); if (!StringUtilities.isBlank(emailId)) resultSet.updateString("EMAIL_ID", aesEncryption.encrypt(emailId)); expiryDate = DateUtils.addDays(Calendar.getInstance().getTime(), Integer.parseInt(getExpiryDays())); resultSet.updateDate("PASSWORD_EXPIRY_DATE", new java.sql.Date(expiryDate.getTime())); System.out.println("Updating user:" + resultSet.getString("LOGIN_NAME")); resultSet.updateRow(); } connection.commit(); }
From source file:org.globus.workspace.scheduler.defaults.DefaultSchedulerAdapterDB.java
/** * This moves significant prepared statement setup times to service * initialization instead of the first time they're used. * * Documentation states that PreparedStatement caches are per pool * connection but preliminary testing indicates it is effective to * just use the first one from the pool. * * @throws org.globus.workspace.persistence.WorkspaceDatabaseException exc *//*from w w w. jav a 2 s . c o m*/ void prepareStatements() throws WorkspaceDatabaseException { final String[] ins = DefaultSchedulerConstants.INSENSITIVE_PREPARED_STATEMENTS; final String[] pstmts = DefaultSchedulerConstants.PREPARED_STATEMENTS; Connection c = null; PreparedStatement pstmt = null; try { c = getConnection(); for (int i = 0; i < ins.length; i++) { pstmt = c.prepareStatement(ins[i], ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); pstmt.close(); } for (int i = 0; i < pstmts.length; i++) { pstmt = c.prepareStatement(pstmts[i]); pstmt.close(); } pstmt = null; } catch (SQLException e) { logger.error("", e); throw new WorkspaceDatabaseException(e); } finally { try { if (pstmt != null) { pstmt.close(); } if (c != null) { returnConnection(c); } } catch (SQLException e) { logger.error("SQLException in finally cleanup", 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//from w w w. ja va 2s .c o 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; }
From source file:org.etudes.jforum.dao.sqlserver.SqlServerPostDAO.java
/** * @see org.etudes.jforum.dao.PostDAO#selectById(int) *///from w ww. ja v a 2 s . co m public Post selectById(int postId) throws Exception { PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.selectById"), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); p.setInt(1, postId); ResultSet rs = p.executeQuery(); Post post = new Post(); if (rs.next()) { post = this.makePost(rs); } rs.close(); p.close(); return post; }
From source file:at.ac.univie.isc.asio.engine.sql.WebRowSetWriter.java
private void properties(final String statement) throws XMLStreamException { // @formatter:off xml.writeStartElement(WRS, "properties"); tag("command", statement); tag("concurrency", ResultSet.CONCUR_UPDATABLE); tag("datasource", null); tag("escape-processing", Boolean.TRUE); tag("fetch-direction", ResultSet.FETCH_FORWARD); tag("fetch-size", 0); tag("isolation-level", Connection.TRANSACTION_NONE); emptyTag("key-columns"); emptyTag("map"); tag("max-field-size", 0); tag("max-rows", 0); tag("query-timeout", 0); tag("read-only", Boolean.TRUE); tag("rowset-type", "ResultSet.TYPE_SCROLL_INSENSITIVE"); // must be constant name ! tag("show-deleted", Boolean.FALSE); emptyTag("table-name"); // <null /> would represent java null - but is invalid according to schema tag("url", null); emptySyncProvider();/* w w w . j a va 2 s . co m*/ xml.writeEndElement(); // @formatter:on }
From source file:solarrecorder.SolarRecorder.java
private void sendSolarUpdate() { String dbString = "jdbc:mysql://localhost:3306/Solar"; try {//from w w w . j a va 2 s . com Connection con = DriverManager.getConnection(dbString, "colin", "Quackquack1"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String SQL = "SELECT * FROM Production"; ResultSet rs = stmt.executeQuery(SQL); rs.moveToInsertRow(); getData(); java.util.Date now = new java.util.Date(); rs.updateDate("Day", new Date(now.getTime())); rs.updateTime("Time", new Time(now.getTime())); for (Object evp : envoyData) { switch (((EnvoyData) evp).getName()) { case "Currently": rs.updateDouble("Current", extractCurrent(((EnvoyData) evp).getValue())); break; case "Today": rs.updateDouble("Today", extractToday(((EnvoyData) evp).getValue())); break; case "Number of Microinverters Online": rs.updateInt("Inverters", Integer.parseInt(((EnvoyData) evp).getValue())); break; } } rs.insertRow(); stmt.close(); rs.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.opennms.model.utils.AssetsUpdater.java
protected static void parseCsv2(final File csv) throws ClassNotFoundException, SQLException, IOException { String sql = m_dbQuery;//ww w .j a v a 2 s.c o m Connection con = createConnection(false); PreparedStatement ps = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(csv))); CSVReader csvReader = new CSVReader(br); String[] line; int lineCnt = 0; while ((line = csvReader.readNext()) != null) { System.out.println("Processing csv line: " + String.valueOf(++lineCnt)); if (line.length != m_fieldMap.size() + 1) { continue; } String foreignSource = m_formatter.formatForeignSource(StringUtils.isBlank(line[0]) ? null : line[0]); System.out.println("Running query for foreignSource: " + foreignSource + " ..."); ps.setString(1, foreignSource); ResultSet rs = ps.executeQuery(); rs.last(); int rows = rs.getRow(); if (rows < 1) { rs.close(); System.out.println("No results found for foreignsource: " + foreignSource + "; continuing to next foreignsource..."); continue; } System.out.println("Found " + rows + " rows."); rs.beforeFirst(); while (rs.next()) { System.out.println("Updating node: " + rs.getInt("nodeid")); Set<Entry<Integer, String>> entrySet = m_fieldMap.entrySet(); for (Entry<Integer, String> entry : entrySet) { int csvField = entry.getKey() - 1; String columnName = entry.getValue(); System.out.println( "\t" + "updating column: " + columnName + " with csv field: " + line[csvField]); rs.updateString(columnName, line[csvField]); } rs.updateRow(); } rs.close(); } try { con.commit(); } catch (SQLException e) { e.printStackTrace(); con.rollback(); } csvReader.close(); ps.close(); con.close(); }
From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java
CassandraStatement(CassandraConnection con, String cql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { this.connection = con; this.cql = cql; this.batchQueries = Lists.newArrayList(); this.consistencyLevel = con.defaultConsistencyLevel; if (!(resultSetType == ResultSet.TYPE_FORWARD_ONLY || resultSetType == ResultSet.TYPE_SCROLL_INSENSITIVE || resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET); this.resultSetType = resultSetType; if (!(resultSetConcurrency == ResultSet.CONCUR_READ_ONLY || resultSetConcurrency == ResultSet.CONCUR_UPDATABLE)) throw new SQLSyntaxErrorException(BAD_TYPE_RSET); this.resultSetConcurrency = resultSetConcurrency; if (!(resultSetHoldability == ResultSet.HOLD_CURSORS_OVER_COMMIT || resultSetHoldability == ResultSet.CLOSE_CURSORS_AT_COMMIT)) throw new SQLSyntaxErrorException(BAD_HOLD_RSET); this.resultSetHoldability = resultSetHoldability; }
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;// w w w .j a va 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:UserPerformance.GetLowerBound.java
public double getUpperB(String GetFixedJobIds) { //get mean from db double Mean_TimePerItem = 0; try {/*from www .j ava2 s . c om*/ 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("Upper Limit for Fixed Job : " + upper); return upper; }