List of usage examples for java.sql PreparedStatement getResultSet
ResultSet getResultSet() throws SQLException;
ResultSet
object. From source file:org.talend.core.model.metadata.builder.database.manager.dbs.OracleExtractManager.java
@Override protected void checkComments(IMetadataConnection metadataConnection, String tableName, List<TdColumn> metadataColumns) { ResultSet keys = null;/* ww w . j a v a 2 s .co m*/ PreparedStatement statement = null; ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance(); try { statement = extractMeta.getConn() .prepareStatement("SELECT COMMENTS FROM USER_COL_COMMENTS WHERE TABLE_NAME='" //$NON-NLS-1$ + tableName + "'"); //$NON-NLS-1$ extractMeta.setQueryStatementTimeout(statement); if (statement.execute()) { keys = statement.getResultSet(); int i = 0; while (keys.next()) { MetadataColumn metadataColumn = metadataColumns.get(i++); metadataColumn.setComment(ManagementTextUtils.filterSpecialChar(keys.getString("COMMENTS"))); //$NON-NLS-1$ } } } catch (Exception e) { log.error(e.toString()); } finally { try { if (keys != null) { keys.close(); } if (statement != null) { statement.close(); } } catch (SQLException e) { log.error(e.toString()); } } }
From source file:Tim.MarkovChains.java
public void getAlternatewords() { Connection con;/*from ww w . ja v a2 s .c om*/ try { con = Tim.db.pool.getConnection(timeout); PreparedStatement s = con.prepareStatement("SELECT `word` FROM `alternate_words`"); s.executeQuery(); ResultSet rs = s.getResultSet(); alternateWords.clear(); while (rs.next()) { alternateWords.add(rs.getString("word")); } con.close(); } catch (SQLException ex) { Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Tim.MarkovChains.java
public void getBadwords() { Connection con;/*from ww w. j av a2 s .c o m*/ try { con = Tim.db.pool.getConnection(timeout); PreparedStatement s = con.prepareStatement("SELECT `word` FROM `bad_words`"); s.executeQuery(); ResultSet rs = s.getResultSet(); String word; badwordPatterns.clear(); while (rs.next()) { word = rs.getString("word"); if (badwordPatterns.get(word) == null) { badwordPatterns.put(word, Pattern.compile("(?ui)(\\W|\\b)(" + Pattern.quote(word) + ")(\\W|\\b)")); } } con.close(); } catch (SQLException ex) { Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Tim.MarkovChains.java
public void getAlternatepairs() { Connection con;/* w w w . j a va 2 s. c om*/ try { con = Tim.db.pool.getConnection(timeout); PreparedStatement s = con.prepareStatement("SELECT `word_one`, `word_two` FROM `bad_pairs`"); s.executeQuery(); ResultSet rs = s.getResultSet(); alternatePairs.clear(); while (rs.next()) { alternatePairs.add(new String[] { rs.getString("word_one"), rs.getString("word_two") }); } con.close(); } catch (SQLException ex) { Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Tim.MarkovChains.java
public void getBadpairs() { Connection con;//from www . j av a 2 s .co m try { con = Tim.db.pool.getConnection(timeout); PreparedStatement s = con.prepareStatement("SELECT `word_one`, `word_two` FROM `bad_pairs`"); s.executeQuery(); ResultSet rs = s.getResultSet(); String word_one, word_two; badpairPatterns.clear(); while (rs.next()) { word_one = rs.getString("word_one"); word_two = rs.getString("word_two"); if (badpairPatterns.get(word_one + ":" + word_two) == null) { badpairPatterns.put(word_one + ":" + word_two, new Pattern[] { Pattern.compile("(?ui)(\\W|\\b)(" + Pattern.quote(word_one) + ")(\\W|\\b)"), Pattern.compile("(?ui)(\\W|\\b)(" + Pattern.quote(word_two) + ")(\\W|\\b)"), }); } } con.close(); } catch (SQLException ex) { Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.netspective.axiom.sql.Query.java
protected boolean checkRecordExistsLogStatistics(ConnectionContext cc, Object[] overrideParams) throws NamingException, SQLException { if (log.isTraceEnabled()) trace(cc, overrideParams);// w ww.j a v a2 s .c o m QueryExecutionLogEntry logEntry = execLog.createNewEntry(cc, this.getQualifiedName()); try { PreparedStatement stmt = createStatement(cc, overrideParams, false, logEntry); logEntry.registerExecSqlBegin(); boolean executeStmtResult = stmt.execute(); logEntry.registerExecSqlEndSuccess(); boolean exists = executeStmtResult && stmt.getResultSet().next(); stmt.close(); return exists; } catch (SQLException e) { logEntry.registerExecSqlEndFailed(); log.error(createExceptionMessage(cc, overrideParams), e); throw e; } finally { logEntry.finalize(cc, log); } }
From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCwoTimeOutTestElement.java
private String resultSetsToString(final PreparedStatement pstmt, boolean result, final int[] out) throws SQLException, UnsupportedEncodingException { final StringBuilder sb = new StringBuilder(); int updateCount = 0; if (!result) { updateCount = pstmt.getUpdateCount(); }/*from www. j a va 2 s.c o m*/ do { if (result) { ResultSet rs = null; try { rs = pstmt.getResultSet(); sb.append(getStringFromResultSet(rs)).append("\n"); // $NON-NLS-1$ } finally { close(rs); } } else { sb.append(updateCount).append(" updates.\n"); } result = pstmt.getMoreResults(); if (!result) { updateCount = pstmt.getUpdateCount(); } } while (result || (updateCount != -1)); if (out != null && pstmt instanceof CallableStatement) { final ArrayList<Object> outputValues = new ArrayList<Object>(); final CallableStatement cs = (CallableStatement) pstmt; sb.append("Output variables by position:\n"); for (int i = 0; i < out.length; i++) { if (out[i] != java.sql.Types.NULL) { final Object o = cs.getObject(i + 1); outputValues.add(o); sb.append("["); sb.append(i + 1); sb.append("] "); sb.append(o); sb.append("\n"); } } final String varnames[] = getVariableNames().split(COMMA); if (varnames.length > 0) { final JMeterVariables jmvars = getThreadContext().getVariables(); for (int i = 0; i < varnames.length && i < outputValues.size(); i++) { final String name = varnames[i].trim(); if (name.length() > 0) { // Save the value in the variable if present final Object o = outputValues.get(i); jmvars.put(name, o == null ? null : o.toString()); } } } } return sb.toString(); }
From source file:com.netspective.axiom.sql.Query.java
protected QueryResultSet executeAndRecordStatistics(ConnectionContext cc, Object[] overrideParams, boolean scrollable) throws NamingException, SQLException { if (log.isTraceEnabled()) trace(cc, overrideParams);/*from w ww .j ava 2 s . com*/ QueryExecutionLogEntry logEntry = execLog.createNewEntry(cc, this.getQualifiedName()); try { PreparedStatement stmt = createStatement(cc, overrideParams, scrollable, logEntry); logEntry.registerExecSqlBegin(); boolean executeStmtResult = stmt.execute(); logEntry.registerExecSqlEndSuccess(); return new QueryResultSet(this, cc, executeStmtResult, stmt.getResultSet(), logEntry); } catch (SQLException e) { logEntry.registerExecSqlEndFailed(); log.error(createExceptionMessage(cc, overrideParams), e); throw e; } finally { logEntry.finalize(cc, log); } }
From source file:org.apache.cayenne.access.jdbc.SQLTemplateAction.java
protected void execute(Connection connection, OperationObserver callback, SQLStatement compiled, Collection<Number> updateCounts) throws SQLException, Exception { long t1 = System.currentTimeMillis(); boolean iteratedResult = callback.isIteratedResult(); PreparedStatement statement = connection.prepareStatement(compiled.getSql()); try {// w w w . java 2 s. c o m bind(statement, compiled.getBindings()); // process a mix of results boolean isResultSet = statement.execute(); boolean firstIteration = true; while (true) { if (firstIteration) { firstIteration = false; } else { isResultSet = statement.getMoreResults(); } if (isResultSet) { ResultSet resultSet = statement.getResultSet(); if (resultSet != null) { try { processSelectResult(compiled, connection, statement, resultSet, callback, t1); } finally { if (!iteratedResult) { resultSet.close(); } } // ignore possible following update counts and bail early on iterated results if (iteratedResult) { break; } } } else { int updateCount = statement.getUpdateCount(); if (updateCount == -1) { break; } updateCounts.add(updateCount); dataNode.getJdbcEventLogger().logUpdateCount(updateCount); } } } finally { if (!iteratedResult) { statement.close(); } } }
From source file:org.hawkular.inventory.impl.tinkerpop.sql.impl.SqlGraph.java
@Override public synchronized SqlEdge getEdge(Object id) { Long eid = getId(id);/* w w w. j ava 2s . c om*/ if (eid == null) { return null; } initConnection(); try { PreparedStatement stmt = statements.getGetEdge(eid); if (!stmt.execute()) { return null; } try (ResultSet rs = stmt.getResultSet()) { if (!rs.next()) { return null; } return SqlEdge.GENERATOR.generate(this, rs); } } catch (SQLException e) { throw new SqlGraphException(e); } }