Skip to content

Instantly share code, notes, and snippets.

@marcelo-ochoa
Created August 24, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelo-ochoa/197ca03238072ca45ea1db46873ee801 to your computer and use it in GitHub Desktop.
Save marcelo-ochoa/197ca03238072ca45ea1db46873ee801 to your computer and use it in GitHub Desktop.
package com.dom.benchmarking.swingbench.testcollection;
import com.dom.benchmarking.swingbench.event.JdbcTaskEvent;
import com.dom.benchmarking.swingbench.kernel.SwingBenchException;
import com.dom.benchmarking.swingbench.kernel.SwingBenchTask;
import com.dom.util.RandomUtilities;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
public final class StressTestSelect extends StressTest {
public StressTestSelect() {
}
public void execute(Map parameters) throws SwingBenchException {
Connection connection = (Connection) parameters.get(SwingBenchTask.JDBC_CONNECTION);
PreparedStatement selPs = null;
ResultSet rs = null;
boolean success = true;
initJdbcTask();
long executeStart = System.nanoTime();
try {
String selectId = RandomUtilities.randomAlpha(32, 32);
selPs = connection.prepareStatement("select * from TESTCOLLECTION where id = ?");
selPs.setString(1, selectId);
rs = selPs.executeQuery();
addSelectStatements(1);
} catch (SQLException ex) {
success = false;
System.out.println(ex);
} finally {
try {
rs.close();
selPs.close();
} catch (SQLException e) {
}
processTransactionEvent(new JdbcTaskEvent(this, getId(), (System.nanoTime() -
executeStart), success, getSelectStatements(), getInsertStatements(), getUpdateStatements(), getDeleteStatements(), getCommitStatements(), getRollbackStatements()));
}
}
public void close() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment