本文整理汇总了Java中java.sql.CallableStatement.executeQuery方法的典型用法代码示例。如果您正苦于以下问题:Java CallableStatement.executeQuery方法的具体用法?Java CallableStatement.executeQuery怎么用?Java CallableStatement.executeQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.CallableStatement
的用法示例。
在下文中一共展示了CallableStatement.executeQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug73070
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Test for Bug#73070 - prepareCall() throws NPE
*
* To test this, we create a basic stored procedure with a
* parameter, call it and check the result.
*/
public void testBug73070() throws Exception {
if (!this.isSetForFabricTest) {
return;
}
this.conn = (FabricMySQLConnection) getNewDefaultDataSource().getConnection(this.username, this.password);
this.conn.setServerGroupName("fabric_test1_global");
this.conn.createStatement().executeUpdate("drop procedure if exists bug73070");
this.conn.createStatement().executeUpdate("create procedure bug73070(in x integer) select x");
CallableStatement stmt = this.conn.prepareCall("{call bug73070(?)}");
stmt.setInt(1, 42);
ResultSet rs = stmt.executeQuery();
rs.next();
assertEquals(42, rs.getInt(1));
rs.close();
stmt.close();
this.conn.createStatement().executeUpdate("drop procedure bug73070");
this.conn.close();
}
示例2: shouldMeasureCallableStatement
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Should measure callable statement.
*
* @throws SQLException
* the SQL exception
*/
@Test
public void shouldMeasureCallableStatement() throws SQLException {
CallableStatement statements[] = { dataSource.getConnection().prepareCall("select"),
dataSource.getConnection().prepareCall("select", 1, 1),
dataSource.getConnection().prepareCall("select", 1, 1, 1) };
for (CallableStatement statement : statements) {
statement.execute();
statement.executeQuery();
statement.executeUpdate();
statement.executeLargeUpdate();
statement.addBatch();
statement.executeBatch();
statement.executeLargeBatch();
}
assertThat(registry.get("jdbc.Statement.Invocations", "select")).isEqualTo(1L * 6 * statements.length);
assertThat(registry.get("jdbc.Statement.Durations", "select")).isEqualTo(123456789L * 6 * statements.length);
}
示例3: getRunsCount
import java.sql.CallableStatement; //导入方法依赖的package包/类
public int getRunsCount( String whereClause ) throws DatabaseAccessException {
Connection connection = getConnection();
String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_runs_count(?) }");
callableStatement.setString(1, whereClause);
rs = callableStatement.executeQuery();
int runsCount = 0;
while (rs.next()) {
runsCount = rs.getInt("runsCount");
logQuerySuccess(sqlLog, "runs", runsCount);
break;
}
return runsCount;
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
}
示例4: getSuitesCount
import java.sql.CallableStatement; //导入方法依赖的package包/类
public int getSuitesCount( String whereClause ) throws DatabaseAccessException {
Connection connection = getConnection();
String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_suites_count(?) }");
callableStatement.setString(1, whereClause);
rs = callableStatement.executeQuery();
int suitesCount = 0;
while (rs.next()) {
suitesCount = rs.getInt("suitesCount");
logQuerySuccess(sqlLog, "suites", suitesCount);
break;
}
return suitesCount;
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
}
示例5: getTablePrimaryIndexName
import java.sql.CallableStatement; //导入方法依赖的package包/类
@Override
public String getTablePrimaryIndexName(java.sql.Connection connection, String tableName) throws SQLException {
String pkName = null;
CallableStatement call = connection.prepareCall("{call sp_pkeys(?)}");
call.setString(1, tableName);
ResultSet rs = call.executeQuery();
try {
while (rs.next()) {
pkName = rs.getString("PK_NAME");
}
} finally {
DbJdbcUtils.closeResultSet(rs);
}
return pkName;
}
示例6: getNumberOfCheckpointsPerQueue
import java.sql.CallableStatement; //导入方法依赖的package包/类
public Map<String, Integer>
getNumberOfCheckpointsPerQueue( String testcaseIds ) throws DatabaseAccessException {
Map<String, Integer> allStatistics = new HashMap<String, Integer>();
String sqlLog = new SqlRequestFormatter().add("testcase ids", testcaseIds).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_number_of_checkpoints_per_queue(?) }");
callableStatement.setString(1, testcaseIds);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
String name = rs.getString("name");
int queueNumbers = rs.getInt("numberOfQueue");
allStatistics.put(name, queueNumbers);
}
logQuerySuccess(sqlLog, "system statistics", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return allStatistics;
}
示例7: testFourParams
import java.sql.CallableStatement; //导入方法依赖的package包/类
public void testFourParams() throws SQLException {
Connection conn = newConnection();
Statement st = conn.createStatement();
st.execute(
"create procedure proc_inout_result_two_params (inout intp int) "
+ " language java reads sql data dynamic result sets 2 external name 'CLASSPATH:org.hsqldb.test.TestStoredProcedure.procWithResultTwo'");
CallableStatement cs =
conn.prepareCall("{call proc_inout_result_two_params(?)}");
cs.setInt(1, 0);
boolean isResult = cs.execute();
assertFalse(isResult);
cs.getMoreResults();
ResultSet rs = cs.getResultSet();
rs.next();
assertEquals(rs.getString(1), "SYSTEM_LOBS");
assertEquals(rs.getString(2), "LOB_IDS");
rs.close();
if (cs.getMoreResults()) {
rs = cs.getResultSet();
rs.next();
assertEquals(rs.getString(1), "SYSTEM_LOBS");
assertEquals(rs.getString(2), "LOBS");
rs.close();
}
rs = cs.executeQuery();
rs.next();
assertEquals(rs.getString(1), "SYSTEM_LOBS");
assertEquals(rs.getString(2), "LOB_IDS");
rs.close();
}
示例8: getMessages
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<Message> getMessages( int startRecord, int recordsCount, String whereClause,
String sortColumn, boolean ascending,
int utcTimeOffset ) throws DatabaseAccessException {
List<Message> messages = new ArrayList<Message>();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord)
.add("records", recordsCount)
.add("where", whereClause)
.add("sort by", sortColumn)
.add("asc", ascending)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_messages(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending
? "ASC"
: "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
Map<Integer, Message> splitMessages = new HashMap<Integer, Message>(); // <parentMessageId, Message>
while (rs.next()) {
Message message = new Message();
message.messageId = rs.getInt("messageId");
message.messageContent = rs.getString("message");
message.messageType = rs.getString("typeName");
if (rs.getTimestamp("timestamp") != null) {
message.setStartTimestamp(rs.getTimestamp("timestamp").getTime());
}
message.setTimeOffset(utcTimeOffset);
message.machineName = rs.getString("machineName");
message.threadName = rs.getString("threadName");
message.parentMessageId = rs.getInt("parentMessageId");
if (message.parentMessageId != 0) {
// split message
if (splitMessages.containsKey(message.parentMessageId)) {
// append to the message - result set is ordered by message ID
Message splitMessage = splitMessages.get(message.parentMessageId);
if (splitMessage.messageId < message.messageId) {
// append at the end
splitMessage.messageContent = splitMessage.messageContent
+ message.messageContent;
} else {
// append at the beginning
splitMessage.messageContent = message.messageContent
+ splitMessage.messageContent;
}
} else {
// first part of the split message
splitMessages.put(message.parentMessageId, message);
messages.add(message);
}
} else {
// single message
messages.add(message);
}
numberRecords++;
}
logQuerySuccess(sqlLog, "messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return messages;
}
示例9: getRunMessages
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<Message> getRunMessages( int startRecord, int recordsCount, String whereClause,
String sortColumn,
boolean ascending,
int utcTimeOffset ) throws DatabaseAccessException {
List<Message> runMessages = new ArrayList<Message>();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord)
.add("records", recordsCount)
.add("where", whereClause)
.add("sort by", sortColumn)
.add("asc", ascending)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_run_messages(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending
? "ASC"
: "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Message runMessage = new Message();
runMessage.messageId = rs.getInt("runMessageId");
runMessage.messageContent = rs.getString("message");
runMessage.messageType = rs.getString("typeName");
if (rs.getTimestamp("timestamp") != null) {
runMessage.setStartTimestamp(rs.getTimestamp("timestamp").getTime());
}
runMessage.setTimeOffset(utcTimeOffset);
runMessage.machineName = rs.getString("machineName");
runMessage.threadName = rs.getString("threadName");
runMessages.add(runMessage);
numberRecords++;
}
logQuerySuccess(sqlLog, "run messages", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return runMessages;
}
示例10: getSystemStatisticDescriptions
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<StatisticDescription> getSystemStatisticDescriptions(
float timeOffset,
String whereClause,
Map<String, String> testcaseAliases,
int utcTimeOffset,
boolean dayLightSavingOn ) throws DatabaseAccessException {
List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset))
.add("whereClause", whereClause)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_system_statistic_descriptions(?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, whereClause);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
StatisticDescription statisticDescription = new StatisticDescription();
statisticDescription.testcaseId = rs.getInt("testcaseId");
// if user has provided testcase alias - use it instead the original testcase name
if (testcaseAliases != null) {
statisticDescription.testcaseName = testcaseAliases.get(String.valueOf(statisticDescription.testcaseId));
}
if (statisticDescription.testcaseName == null) {
statisticDescription.testcaseName = rs.getString("testcaseName");
}
long startTimestamp = rs.getInt("testcaseStarttime");
if (dayLightSavingOn) {
startTimestamp += 3600; // add 1h to time stamp
}
statisticDescription.setStartTimestamp(startTimestamp);
statisticDescription.setTimeOffset(utcTimeOffset);
statisticDescription.machineId = rs.getInt("machineId");
statisticDescription.machineName = rs.getString("machineName");
statisticDescription.statisticTypeId = rs.getInt("statsTypeId");
statisticDescription.statisticName = rs.getString("name");
statisticDescription.unit = rs.getString("units");
statisticDescription.params = rs.getString("params");
statisticDescription.parent = rs.getString("parentName");
statisticDescription.internalName = rs.getString("internalName");
statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
statisticDescription.minValue = rs.getFloat("statsMinValue");
statisticDescription.maxValue = rs.getFloat("statsMaxValue");
statisticDescription.avgValue = rs.getFloat("statsAvgValue");
statisticDescriptions.add(statisticDescription);
numberRecords++;
}
logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return statisticDescriptions;
}
示例11: getCheckpointStatisticDescriptions
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<StatisticDescription> getCheckpointStatisticDescriptions( float timeOffset,
String whereClause,
Set<String> expectedSingleActionUIDs,
int utcTimeOffset,
boolean dayLightSavingOn ) throws DatabaseAccessException {
List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset))
.add("where clause", whereClause)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistic_descriptions(?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, whereClause);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
StatisticDescription statisticDescription = new StatisticDescription();
statisticDescription.testcaseId = rs.getInt("testcaseId");
if (statisticDescription.testcaseName == null) {
statisticDescription.testcaseName = rs.getString("testcaseName");
}
long startTimestamp = rs.getInt("testcaseStarttime");
if (dayLightSavingOn) {
startTimestamp += 3600; // add 1h to time stamp
}
statisticDescription.setStartTimestamp(startTimestamp);
statisticDescription.setTimeOffset(utcTimeOffset);
statisticDescription.machineId = 0; // Checkpoints will be collected and displayed for testcase
statisticDescription.machineName = MACHINE_NAME_FOR_ATS_AGENTS;
statisticDescription.queueName = rs.getString("queueName");
statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
statisticDescription.minValue = rs.getInt("statsMinValue");
statisticDescription.avgValue = rs.getInt("statsAvgValue");
statisticDescription.maxValue = rs.getInt("statsMaxValue");
statisticDescription.statisticName = rs.getString("name");
statisticDescription.unit = "ms"; // "statsUnit" field is null for checkpoint statistics, because the action response times are always measured in "ms"
String actionUid = statisticDescription.testcaseId + "->" + statisticDescription.machineId
+ "->" + statisticDescription.queueName + "->"
+ statisticDescription.statisticName;
// add to single statistics
if (expectedSingleActionUIDs.isEmpty() || expectedSingleActionUIDs.contains(actionUid)) {
statisticDescriptions.add(statisticDescription);
numberRecords++;
}
}
logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return statisticDescriptions;
}
示例12: getSystemStatistics
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<Statistic> getSystemStatistics( float timeOffset,
String testcaseIds,
String machineIds,
String statsTypeIds,
int utcTimeOffset,
boolean dayLightSavingOn )
throws DatabaseAccessException {
List<Statistic> allStatistics = new ArrayList<Statistic>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset))
.add("testcase ids", testcaseIds)
.add("machine ids", machineIds)
.add("stats type ids", statsTypeIds)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_system_statistics(?, ?, ?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
callableStatement.setString(3, machineIds);
callableStatement.setString(4, statsTypeIds);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
Statistic statistic = new Statistic();
statistic.statisticTypeId = rs.getInt("statsTypeId");
statistic.name = rs.getString("statsName");
statistic.parentName = rs.getString("statsParent");
statistic.unit = rs.getString("statsUnit");
statistic.value = rs.getFloat("value");
statistic.setDate(rs.getString("statsAxis"));
long startTimestamp = rs.getInt("statsAxisTimestamp");
if (dayLightSavingOn) {
startTimestamp += 3600; // add 1h to time stamp
}
statistic.setStartTimestamp(startTimestamp);
statistic.setTimeOffset(utcTimeOffset);
statistic.machineId = rs.getInt("machineId");
statistic.testcaseId = rs.getInt("testcaseId");
numberRecords++;
// add the combined statistics to the others
allStatistics.add(statistic);
}
logQuerySuccess(sqlLog, "system statistics", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return allStatistics;
}
示例13: getCheckpointsSummary
import java.sql.CallableStatement; //导入方法依赖的package包/类
public List<CheckpointSummary> getCheckpointsSummary( String whereClause, String sortColumn,
boolean ascending ) throws DatabaseAccessException {
List<CheckpointSummary> checkpoints = new ArrayList<CheckpointSummary>();
String sqlLog = new SqlRequestFormatter().add("where", whereClause)
.add("sort by", sortColumn)
.add("asc", ascending)
.format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_checkpoints_summary(?, ?, ?) }");
callableStatement.setString(1, "where " + whereClause);
callableStatement.setString(2, sortColumn);
callableStatement.setString(3, (ascending
? "ASC"
: "DESC"));
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
CheckpointSummary checkpointSummary = new CheckpointSummary();
checkpointSummary.checkpointSummaryId = rs.getInt("checkpointSummaryId");
checkpointSummary.name = rs.getString("name");
checkpointSummary.numRunning = rs.getInt("numRunning");
checkpointSummary.numPassed = rs.getInt("numPassed");
checkpointSummary.numFailed = rs.getInt("numFailed");
checkpointSummary.numTotal = checkpointSummary.numRunning + checkpointSummary.numPassed
+ checkpointSummary.numFailed;
checkpointSummary.minResponseTime = rs.getInt("minResponseTime");
if (checkpointSummary.minResponseTime == Integer.MAX_VALUE) {
checkpointSummary.minResponseTime = 0;
}
checkpointSummary.avgResponseTime = rs.getFloat("avgResponseTime");
checkpointSummary.maxResponseTime = rs.getInt("maxResponseTime");
checkpointSummary.minTransferRate = rs.getFloat("minTransferRate");
if (checkpointSummary.minTransferRate == Integer.MAX_VALUE) {
checkpointSummary.minTransferRate = 0.0F;
}
checkpointSummary.avgTransferRate = rs.getFloat("avgTransferRate");
checkpointSummary.maxTransferRate = rs.getFloat("maxTransferRate");
checkpointSummary.transferRateUnit = rs.getString("transferRateUnit");
checkpoints.add(checkpointSummary);
numberRecords++;
}
logQuerySuccess(sqlLog, "checkpoints summary", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return checkpoints;
}
示例14: execute
import java.sql.CallableStatement; //导入方法依赖的package包/类
public String execute(IQuery query) throws Exception {
CallableStatement stmt = connection.prepareCall(query.getSql());
ResultSet rs = stmt.executeQuery();
String result = XmlEncoder.getInstance().encode(rs);
return result;
}
示例15: testSPCache
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests parsing of stored procedures
*
* @throws Exception
* if an error occurs.
*/
public void testSPCache() throws Exception {
if (versionMeetsMinimum(5, 0)) {
CallableStatement storedProc = null;
createProcedure("testSpParse", "(IN FOO VARCHAR(15))\nBEGIN\nSELECT 1;\nend\n");
int numIterations = 10;
long startTime = System.currentTimeMillis();
for (int i = 0; i < numIterations; i++) {
storedProc = this.conn.prepareCall("{call testSpParse(?)}");
storedProc.close();
}
long elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Standard parsing/execution: " + elapsedTime + " ms");
storedProc = this.conn.prepareCall("{call testSpParse(?)}");
storedProc.setString(1, "abc");
this.rs = storedProc.executeQuery();
assertTrue(this.rs.next());
assertTrue(this.rs.getInt(1) == 1);
Properties props = new Properties();
props.setProperty("cacheCallableStmts", "true");
Connection cachedSpConn = getConnectionWithProps(props);
startTime = System.currentTimeMillis();
for (int i = 0; i < numIterations; i++) {
storedProc = cachedSpConn.prepareCall("{call testSpParse(?)}");
storedProc.close();
}
elapsedTime = System.currentTimeMillis() - startTime;
System.out.println("Cached parse stage: " + elapsedTime + " ms");
storedProc = cachedSpConn.prepareCall("{call testSpParse(?)}");
storedProc.setString(1, "abc");
this.rs = storedProc.executeQuery();
assertTrue(this.rs.next());
assertTrue(this.rs.getInt(1) == 1);
}
}