Java Code Examples for java.sql.PreparedStatement#getMoreResults()
The following examples show how to use
java.sql.PreparedStatement#getMoreResults() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultSetReturnImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public ResultSet execute(PreparedStatement statement) { // sql logged by StatementPreparerImpl try { final ResultSet rs; try { jdbcExecuteStatementStart(); if ( !statement.execute() ) { while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) { // do nothing until we hit the resultset } } rs = statement.getResultSet(); } finally { jdbcExecuteStatementEnd(); } postExtract( rs, statement ); return rs; } catch (SQLException e) { throw sqlExceptionHelper.convert( e, "could not execute statement" ); } }
Example 2
Source File: Swarm.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static DUnitMethodInfo getOrCreateDUnitMethodInfo(String name, int class_id) throws SQLException { PreparedStatement ps = Database .prepareStatement("SELECT id from dunit_test_method where name=? and test_class_id=?"); ps.setString(1, name); ps.setInt(2, class_id); ResultSet rs = ps.executeQuery(); if (rs.next()) { DUnitMethodInfo duci = new DUnitMethodInfo(rs.getInt(1), name, class_id); return duci; } else { PreparedStatement psi = Database .prepareStatement("INSERT INTO dunit_test_method(name,test_class_id) values(?,?);SELECT currval('dunit_test_method_id_seq');"); psi.setString(1, name); psi.setInt(2, class_id); psi.execute(); psi.getMoreResults(); ResultSet rsi = psi.getResultSet(); rsi.next(); System.out.println("2XXXXX:" + rsi.getInt(1)); return new DUnitMethodInfo(rsi.getInt(1), name, class_id); } }
Example 3
Source File: Swarm.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static DUnitClassInfo getOrCreateDUnitClassInfo(String name) throws SQLException { PreparedStatement ps = Database .prepareStatement("SELECT ID,NAME from dunit_test_class where name=?"); ps.setString(1, name); ResultSet rs = ps.executeQuery(); if (rs.next()) { DUnitClassInfo duci = new DUnitClassInfo(rs.getInt(1), rs.getString(2)); return duci; } else { PreparedStatement psi = Database .prepareStatement("INSERT INTO dunit_test_class(name) values(?);SELECT currval('dunit_test_class_id_seq');"); psi.setString(1, name); psi.execute(); psi.getMoreResults(); ResultSet rsi = psi.getResultSet(); rsi.next(); System.out.println("XXXXX:" + rsi.getInt(1)); return new DUnitClassInfo(rsi.getInt(1), name); } }
Example 4
Source File: Swarm.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public static DUnitClassInfo getOrCreateDUnitClassInfo(String name) throws SQLException { PreparedStatement ps = Database .prepareStatement("SELECT ID,NAME from dunit_test_class where name=?"); ps.setString(1, name); ResultSet rs = ps.executeQuery(); if (rs.next()) { DUnitClassInfo duci = new DUnitClassInfo(rs.getInt(1), rs.getString(2)); return duci; } else { PreparedStatement psi = Database .prepareStatement("INSERT INTO dunit_test_class(name) values(?);SELECT currval('dunit_test_class_id_seq');"); psi.setString(1, name); psi.execute(); psi.getMoreResults(); ResultSet rsi = psi.getResultSet(); rsi.next(); System.out.println("XXXXX:" + rsi.getInt(1)); return new DUnitClassInfo(rsi.getInt(1), name); } }
Example 5
Source File: ProcedureJdbcTemplate.java From opscenter with Apache License 2.0 | 6 votes |
/** * 创建结果集列表 * @param cstmt * @param rs * @return List<List<Map<String, Object>>> * @throws IOException */ public List<List<Map<String, Object>>> createRows(PreparedStatement ps, ResultSet rs) throws IOException{ List<List<Map<String, Object>>> list = new ArrayList<>(); RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<>(new ColumnMapRowMapper()); boolean label = true; int health = 0; while(label){ try { rs=ps.getResultSet(); if(rs !=null){ list.add(rse.extractData(rs)); label = ps.getMoreResults(); health++; if(health > MAX_LOOP) break; continue; } label = false; } catch (SQLException e) { label = false; } } return list; }
Example 6
Source File: IdentityGenerator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Serializable executeAndExtract(PreparedStatement insert) throws SQLException { if ( !insert.execute() ) { while ( !insert.getMoreResults() && insert.getUpdateCount() != -1 ) { // do nothing until we hit the rsult set containing the generated id } } ResultSet rs = insert.getResultSet(); try { return IdentifierGeneratorFactory.getGeneratedIdentity( rs, persister.getIdentifierType() ); } finally { rs.close(); } }
Example 7
Source File: JdbcStatement.java From quarks with Apache License 2.0 | 5 votes |
private void executeStatement(T tuple, List<R> results) { nTuples++; try { logger.debug("executing statement nTuples={} nTuplesFailed={}", nTuples, nTuplesFailed); Connection cn = connector.getConnection(this); PreparedStatement stmt = getPreparedStatement(cn); paramSetter.setParameters(tuple, stmt); boolean hasResult = stmt.execute(); if (resultsHandler != null) { if (!hasResult) { resultsHandler.handleResults(tuple, null/*rs*/, null/*exc*/, (result) -> results.add(result)); } else { do { try (ResultSet rs = stmt.getResultSet()) { resultsHandler.handleResults(tuple, rs, null/*exc*/, (result) -> results.add(result)); } } while (stmt.getMoreResults()); } } } catch (Exception e) { nTuplesFailed++; logger.trace("executing statement failed nTuples={} nTuplesFailed={}", nTuples, nTuplesFailed); if (resultsHandler != null) { try { resultsHandler.handleResults(tuple, null/*rs*/, e, (result) -> results.add(result)); } catch (Exception e2) { logger.error("failure result handler failed", e2); } } closeStmt(); connector.statementFailed(this, e); } }
Example 8
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public List<ChatBase> getChatsByStartRow(long startRowID) throws SQLException { List<ChatBase> chats = new ArrayList<>(); String selectChatsStatementString = "SELECT * FROM " + CHAT_TABLE + " WHERE " + COLUMN_CHAT_ROWID + " >= ?"; PreparedStatement selectChatsStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatsStatementString); selectChatsStatement.setLong(1, startRowID); boolean isResultSet = selectChatsStatement.execute(); while(true) { if(isResultSet) { ResultSet resultSet = selectChatsStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_CHAT_ROWID); ChatBase chat = getChatByRow(resultInt); if (chat != null) { chats.add(chat); } } resultSet.close(); } else { if(selectChatsStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatsStatement.getMoreResults(); } selectChatsStatement.close(); return chats; }
Example 9
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public List<Handle> getHandlesByAmount(long amount) throws SQLException { List<Handle> handles = new ArrayList<>(); String selectHandlesStatementString = "SELECT * FROM (SELECT * FROM " + HANDLE_TABLE + " ORDER BY " + COLUMN_HANDLE_ROWID + " DESC LIMIT ?) ORDER BY " + COLUMN_HANDLE_ROWID + " ASC"; PreparedStatement selectHandlesStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectHandlesStatementString); selectHandlesStatement.setLong(1, amount); boolean isResultSet = selectHandlesStatement.execute(); while(true) { if(isResultSet) { ResultSet resultSet = selectHandlesStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_HANDLE_ROWID); Handle handle = getHandleByRow(resultInt); if(handle != null) { handles.add(handle); } } resultSet.close(); } else { if(selectHandlesStatement.getUpdateCount() == -1) { break; } } isResultSet = selectHandlesStatement.getMoreResults(); } selectHandlesStatement.close(); return handles; }
Example 10
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public List<Message> getMessagesByAmount(long amount) throws SQLException { List<Message> messages = new ArrayList<>(); String selectMessagesStatementString = "SELECT * FROM (SELECT * FROM " + MESSAGE_TABLE + " ORDER BY " + COLUMN_MESSAGE_ROWID + " DESC LIMIT ?) ORDER BY " + COLUMN_MESSAGE_ROWID + " ASC"; PreparedStatement selectMessagesStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectMessagesStatementString); selectMessagesStatement.setLong(1, amount); boolean isResultSet = selectMessagesStatement.execute(); while(true) { if(isResultSet) { ResultSet resultSet = selectMessagesStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_MESSAGE_ROWID); Message message = getMessageByRow(resultInt); if (message != null) { messages.add(message); } } resultSet.close(); } else { if(selectMessagesStatement.getUpdateCount() == -1) { break; } } isResultSet = selectMessagesStatement.getMoreResults(); } selectMessagesStatement.close(); return messages; }
Example 11
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public HashMap<Long, String> getSortedChatsWithGuid() throws SQLException { HashMap<Long, String> chatRowGuidPair = new HashMap<>(); String selectChatStatementString = "SELECT " + CHAT_TABLE + "." + COLUMN_CHAT_GUID + ", " + COLUMN_CHAT_MESSAGE_CHAT_ID + ", MAX(" + COLUMN_CHAT_MESSAGE_MESSAGE_ID + ")" + " FROM " + CHAT_MESSAGE_JOIN_TABLE + " INNER JOIN " + CHAT_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_CHAT_ID + " = " + CHAT_TABLE + "." + COLUMN_CHAT_ROWID + " INNER JOIN " + MESSAGE_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_ROWID + " WHERE " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_TEXT + " IS NOT NULL " + " GROUP BY " + COLUMN_CHAT_MESSAGE_CHAT_ID + " ORDER BY " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " DESC"; PreparedStatement selectChatStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatStatementString); boolean isResultSet = selectChatStatement.execute(); long i = 0L; while(true) { if(isResultSet) { ResultSet resultSet = selectChatStatement.getResultSet(); while(resultSet.next()) { String resultString = resultSet.getString(COLUMN_CHAT_GUID); chatRowGuidPair.put(i, resultString); i++; } resultSet.close(); } else { if(selectChatStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatStatement.getMoreResults(); } selectChatStatement.close(); return chatRowGuidPair; }
Example 12
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public HashMap<Long, Long> getSortedChatsWithRow() throws SQLException { HashMap<Long, Long> positionRowIdPair = new HashMap<>(); String selectChatStatementString = "SELECT " + COLUMN_CHAT_MESSAGE_CHAT_ID + ", MAX(" + COLUMN_CHAT_MESSAGE_MESSAGE_ID + ") FROM " + CHAT_MESSAGE_JOIN_TABLE + " INNER JOIN " + MESSAGE_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_ROWID + " WHERE " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_TEXT + " IS NOT NULL " + " GROUP BY " + COLUMN_CHAT_MESSAGE_CHAT_ID + " ORDER BY " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " DESC"; PreparedStatement selectChatStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatStatementString); boolean isResultSet = selectChatStatement.execute(); long i = 0L; while(true) { if(isResultSet) { ResultSet resultSet = selectChatStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_CHAT_MESSAGE_CHAT_ID); positionRowIdPair.put(i, resultInt); i++; } resultSet.close(); } else { if(selectChatStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatStatement.getMoreResults(); } selectChatStatement.close(); return positionRowIdPair; }
Example 13
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public long getChatRowPositionByGuid(String guid) throws SQLException { Long rowIdReturn = null; String selectChatStatementString = "SELECT " + CHAT_TABLE + "." + COLUMN_CHAT_GUID + ", " + COLUMN_CHAT_MESSAGE_CHAT_ID + ", MAX(" + COLUMN_CHAT_MESSAGE_MESSAGE_ID + ")" + " FROM " + CHAT_MESSAGE_JOIN_TABLE + " INNER JOIN " + CHAT_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_CHAT_ID + " = " + CHAT_TABLE + "." + COLUMN_CHAT_ROWID + " INNER JOIN " + MESSAGE_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_ROWID + " WHERE " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_TEXT + " IS NOT NULL " + " GROUP BY " + COLUMN_CHAT_MESSAGE_CHAT_ID + " ORDER BY " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " DESC"; PreparedStatement selectChatStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatStatementString); boolean isResultSet = selectChatStatement.execute(); long i = 0L; while(true) { if(isResultSet) { ResultSet resultSet = selectChatStatement.getResultSet(); while(resultSet.next()) { String resultString = resultSet.getString(COLUMN_CHAT_GUID); if (resultString.equals(guid)){ rowIdReturn = i; break; } i++; } resultSet.close(); } else { if(selectChatStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatStatement.getMoreResults(); } selectChatStatement.close(); return rowIdReturn; }
Example 14
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public long getChatRowPositionByRowId(long rowId) throws SQLException { Long rowIdReturn = null; String selectChatStatementString = "SELECT " + COLUMN_CHAT_MESSAGE_CHAT_ID + ", MAX(" + COLUMN_CHAT_MESSAGE_MESSAGE_ID + ") FROM " + CHAT_MESSAGE_JOIN_TABLE + " INNER JOIN " + MESSAGE_TABLE + " ON " + CHAT_MESSAGE_JOIN_TABLE + "." + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_ROWID + " WHERE " + MESSAGE_TABLE + "." + COLUMN_MESSAGE_TEXT + " IS NOT NULL " + " GROUP BY " + COLUMN_CHAT_MESSAGE_CHAT_ID + " ORDER BY " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " DESC"; PreparedStatement selectChatStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatStatementString); boolean isResultSet = selectChatStatement.execute(); long i = 0L; while(true) { if(isResultSet) { ResultSet resultSet = selectChatStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_CHAT_MESSAGE_CHAT_ID); if (rowId == resultInt){ rowIdReturn = i; break; } i++; } resultSet.close(); } else { if(selectChatStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatStatement.getMoreResults(); } selectChatStatement.close(); return rowIdReturn; }
Example 15
Source File: DatabaseManager.java From weMessage with GNU Affero General Public License v3.0 | 5 votes |
public List<JSONAction> getQueuedActions(String deviceId) throws IOException, SQLException { List<JSONAction> actionQueue = new ArrayList<>(); String selectAwaitingDevicesStatementString = "SELECT * FROM " + TABLE_ACTION_QUEUE + " WHERE " + COLUMN_QUEUE_ACTION_DEVICES_WAITING + " LIKE ?"; PreparedStatement selectAwaitingDevicesStatement = getServerDatabaseConnection().prepareStatement(selectAwaitingDevicesStatementString); selectAwaitingDevicesStatement.setString(1, "%" + deviceId + "%"); boolean isResultSet = selectAwaitingDevicesStatement.execute(); while(true) { if(isResultSet) { ResultSet resultSet = selectAwaitingDevicesStatement.getResultSet(); while(resultSet.next()) { if (resultSet.getString(COLUMN_QUEUE_ACTION_ACCOUNT).equalsIgnoreCase(messageServer.getConfiguration().getAccountEmail())) { String actionJSON = resultSet.getString(COLUMN_QUEUE_ACTION_JSON); JSONAction jsonAction = new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, byteArrayAdapter).create().fromJson(actionJSON, JSONAction.class); actionQueue.add(jsonAction); } } resultSet.close(); } else { if(selectAwaitingDevicesStatement.getUpdateCount() == -1) { break; } } isResultSet = selectAwaitingDevicesStatement.getMoreResults(); } selectAwaitingDevicesStatement.close(); return actionQueue; }
Example 16
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 4 votes |
public Message getMessageByGuid(String guid) throws SQLException { String selectStatementString = "SELECT * FROM " + MESSAGE_TABLE + " WHERE " + COLUMN_MESSAGE_GUID + " = ?"; PreparedStatement selectStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectStatementString); selectStatement.setString(1, guid); ResultSet resultSet = selectStatement.executeQuery(); if (!resultSet.isBeforeFirst()){ resultSet.close(); selectStatement.close(); return null; } Handle handle = getHandleByRow(resultSet.getLong(COLUMN_MESSAGE_HANDLE_ID)); long messageRow = resultSet.getLong(COLUMN_MESSAGE_ROWID); String selectChatMessageStatementString = "SELECT * FROM " + CHAT_MESSAGE_JOIN_TABLE + " WHERE " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = ?"; PreparedStatement selectChatMessageStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatMessageStatementString); selectChatMessageStatement.setLong(1, messageRow); ResultSet resultChatMessageSet = selectChatMessageStatement.executeQuery(); ChatBase chat; try { long theResultInt = resultChatMessageSet.getLong(COLUMN_CHAT_MESSAGE_CHAT_ID); chat = getChatByRow(theResultInt); }catch(Exception ex){ return null; } List<Attachment> attachments = new ArrayList<>(); String selectMessageAttachmentString = "SELECT * FROM " + MESSAGE_ATTACHMENT_TABLE + " WHERE " + COLUMN_MESSAGE_ATTACHMENT_MESSAGE_ID + " = ?"; PreparedStatement selectMessageAttachmentStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectMessageAttachmentString); selectMessageAttachmentStatement.setLong(1, messageRow); boolean isResultSet = selectMessageAttachmentStatement.execute(); while(true) { if(isResultSet) { ResultSet theResultSet = selectMessageAttachmentStatement.getResultSet(); while(theResultSet.next()) { long resultInt = theResultSet.getLong(COLUMN_MESSAGE_ATTACHMENT_ATTACHMENT_ID); attachments.add(getAttachmentByRow(resultInt)); } theResultSet.close(); } else { if(selectMessageAttachmentStatement.getUpdateCount() == -1) { break; } } isResultSet = selectMessageAttachmentStatement.getMoreResults(); } Message message = buildMessage(resultSet, chat, handle, attachments); resultSet.close(); resultChatMessageSet.close(); selectStatement.close(); selectChatMessageStatement.close(); selectMessageAttachmentStatement.close(); return message; }
Example 17
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 4 votes |
public Message getMessageByRow(long rowID) throws SQLException { String selectStatementString = "SELECT * FROM " + MESSAGE_TABLE + " WHERE " + COLUMN_MESSAGE_ROWID + " = ?"; PreparedStatement selectStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectStatementString); selectStatement.setLong(1, rowID); ResultSet resultSet = selectStatement.executeQuery(); if (!resultSet.isBeforeFirst()){ resultSet.close(); selectStatement.close(); return null; } Handle handle = getHandleByRow(resultSet.getLong(COLUMN_MESSAGE_HANDLE_ID)); long messageRow = resultSet.getLong(COLUMN_MESSAGE_ROWID); String selectChatMessageStatementString = "SELECT * FROM " + CHAT_MESSAGE_JOIN_TABLE + " WHERE " + COLUMN_CHAT_MESSAGE_MESSAGE_ID + " = ?"; PreparedStatement selectChatMessageStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatMessageStatementString); selectChatMessageStatement.setLong(1, messageRow); ResultSet resultChatMessageSet = selectChatMessageStatement.executeQuery(); ChatBase chat; try { long theResultInt = resultChatMessageSet.getLong(COLUMN_CHAT_MESSAGE_CHAT_ID); chat = getChatByRow(theResultInt); }catch(Exception ex){ return null; } List<Attachment> attachments = new ArrayList<>(); String selectMessageAttachmentString = "SELECT * FROM " + MESSAGE_ATTACHMENT_TABLE + " WHERE " + COLUMN_MESSAGE_ATTACHMENT_MESSAGE_ID + " = ?"; PreparedStatement selectMessageAttachmentStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectMessageAttachmentString); selectMessageAttachmentStatement.setLong(1, messageRow); boolean isResultSet = selectMessageAttachmentStatement.execute(); while(true) { if(isResultSet) { ResultSet theResultSet = selectMessageAttachmentStatement.getResultSet(); while(theResultSet.next()) { long resultInt = theResultSet.getLong(COLUMN_MESSAGE_ATTACHMENT_ATTACHMENT_ID); attachments.add(getAttachmentByRow(resultInt)); } theResultSet.close(); } else { if(selectMessageAttachmentStatement.getUpdateCount() == -1) { break; } } isResultSet = selectMessageAttachmentStatement.getMoreResults(); } Message message = buildMessage(resultSet, chat, handle, attachments); resultSet.close(); resultChatMessageSet.close(); selectStatement.close(); selectChatMessageStatement.close(); selectMessageAttachmentStatement.close(); return message; }
Example 18
Source File: MessagesDatabase.java From weMessage with GNU Affero General Public License v3.0 | 4 votes |
public ChatBase getChatByIdentifier(String chatIdentifier) throws SQLException { String selectChatStatementString = "SELECT * FROM " + CHAT_TABLE + " WHERE " + COLUMN_CHAT_IDENTIFIER + " = ?"; PreparedStatement selectChatStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatStatementString); selectChatStatement.setString(1, chatIdentifier); ResultSet chatResultSet = selectChatStatement.executeQuery(); if (!chatResultSet.isBeforeFirst()){ chatResultSet.close(); selectChatStatement.close(); return null; } List<Handle> handles = new ArrayList<>(); String selectChatHandleStatementString = "SELECT * FROM " + CHAT_HANDLES_TABLE + " WHERE " + COLUMN_CHAT_HANDLE_CHAT_ID + " = ?"; PreparedStatement selectChatHandleStatement = getDatabaseManager().getChatDatabaseConnection().prepareStatement(selectChatHandleStatementString); selectChatHandleStatement.setLong(1, chatResultSet.getLong(COLUMN_CHAT_ROWID)); boolean isResultSet = selectChatHandleStatement.execute(); while(true) { if(isResultSet) { ResultSet resultSet = selectChatHandleStatement.getResultSet(); while(resultSet.next()) { long resultInt = resultSet.getLong(COLUMN_CHAT_HANDLE_HANDLE_ID); handles.add(getHandleByRow(resultInt)); } resultSet.close(); } else { if(selectChatHandleStatement.getUpdateCount() == -1) { break; } } isResultSet = selectChatHandleStatement.getMoreResults(); } ChatBase chat = buildChat(chatResultSet, handles); chatResultSet.close(); selectChatStatement.close(); selectChatHandleStatement.close(); return chat; }
Example 19
Source File: Swarm.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public static DUnitRun generateNewDUnitRun() throws SQLException, IOException { Properties gfvp = new Properties(); gfvp .load(GemFireCacheImpl.class .getResourceAsStream("/com/gemstone/gemfire/internal/GemFireVersion.properties")); PreparedStatement ps = Database .prepareStatement("INSERT INTO dunit_run(user_name,path,sites,revision,branch,os_name,os_version,java_version,java_vm_version,java_vm_vendor) values(?,?,?,?,?,?,?,?,?,?);SELECT currval('dunit_run_id_seq');"); String user_name = System.getProperty("user.name"); String path = System.getProperty("user.dir"); int sites = Integer.parseInt((String)TestConfig.getInstance() .getSystemProperties().get("dunitSites")); String revision = gfvp.getProperty("Source-Revision"); String branch = gfvp.getProperty("Source-Repository"); String os_name = System.getProperty("os.name"); String os_version = System.getProperty("os.version"); String java_version = System.getProperty("java.version"); String java_vm_version = System.getProperty("java.vm.version"); String java_vm_vendor = System.getProperty("java.vm.vendor"); ps.setString(1, user_name); ps.setString(2, path); ps.setInt(3, sites); ps.setString(4, revision); ps.setString(5, branch); ps.setString(6, os_name); ps.setString(7, os_version); ps.setString(8, java_version); ps.setString(9, java_vm_version); ps.setString(10, java_vm_vendor); ps.execute(); ps.getMoreResults(); ResultSet rsi = ps.getResultSet(); rsi.next(); DUnitRun du = new DUnitRun(rsi.getInt(1), user_name, path, sites, revision, branch, os_name, os_version, java_version, java_vm_version, java_vm_vendor, new Date()); return du; }
Example 20
Source File: SwPreparedStatementTest.java From skywalking with Apache License 2.0 | 4 votes |
@Test public void testPreparedStatementConfig() throws SQLException { PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES( ? , ?)", 1); preparedStatement.setInt(1, 1); preparedStatement.setString(2, "a"); preparedStatement.getUpdateCount(); preparedStatement.setFetchDirection(1); preparedStatement.getFetchDirection(); preparedStatement.getResultSetConcurrency(); preparedStatement.getResultSetType(); preparedStatement.isClosed(); preparedStatement.setPoolable(false); preparedStatement.isPoolable(); preparedStatement.getWarnings(); preparedStatement.clearWarnings(); preparedStatement.setCursorName("test"); preparedStatement.setMaxFieldSize(11); preparedStatement.getMaxFieldSize(); preparedStatement.setMaxRows(10); preparedStatement.getMaxRows(); preparedStatement.getParameterMetaData(); preparedStatement.setEscapeProcessing(true); preparedStatement.setFetchSize(1); preparedStatement.getFetchSize(); preparedStatement.setQueryTimeout(1); preparedStatement.getQueryTimeout(); Connection connection = preparedStatement.getConnection(); preparedStatement.execute(); preparedStatement.getMoreResults(); preparedStatement.getMoreResults(1); preparedStatement.getResultSetHoldability(); preparedStatement.getMetaData(); preparedStatement.getResultSet(); preparedStatement.close(); verify(mysqlPreparedStatement).getUpdateCount(); verify(mysqlPreparedStatement).getMoreResults(); verify(mysqlPreparedStatement).setFetchDirection(anyInt()); verify(mysqlPreparedStatement).getFetchDirection(); verify(mysqlPreparedStatement).getResultSetType(); verify(mysqlPreparedStatement).isClosed(); verify(mysqlPreparedStatement).setPoolable(anyBoolean()); verify(mysqlPreparedStatement).getWarnings(); verify(mysqlPreparedStatement).clearWarnings(); verify(mysqlPreparedStatement).setCursorName(anyString()); verify(mysqlPreparedStatement).setMaxFieldSize(anyInt()); verify(mysqlPreparedStatement).getMaxFieldSize(); verify(mysqlPreparedStatement).setMaxRows(anyInt()); verify(mysqlPreparedStatement).getMaxRows(); verify(mysqlPreparedStatement).setEscapeProcessing(anyBoolean()); verify(mysqlPreparedStatement).getResultSetConcurrency(); verify(mysqlPreparedStatement).getResultSetConcurrency(); verify(mysqlPreparedStatement).getResultSetType(); verify(mysqlPreparedStatement).getMetaData(); verify(mysqlPreparedStatement).getParameterMetaData(); verify(mysqlPreparedStatement).getMoreResults(anyInt()); verify(mysqlPreparedStatement).setFetchSize(anyInt()); verify(mysqlPreparedStatement).getFetchSize(); verify(mysqlPreparedStatement).getQueryTimeout(); verify(mysqlPreparedStatement).setQueryTimeout(anyInt()); verify(mysqlPreparedStatement).getResultSet(); assertThat(connection, CoreMatchers.<Connection>is(swConnection)); }