Skip to content

Instantly share code, notes, and snippets.

@jordansjones
Created August 22, 2012 03:31
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 jordansjones/3422081 to your computer and use it in GitHub Desktop.
Save jordansjones/3422081 to your computer and use it in GitHub Desktop.
Test Case
public class App {
public static void main(String[] args) throws SQLException {
final String username = "jordan";
final String password = "test";
final String db = "test";
final String query = "SELECT SUM(UpVotes), COUNT(Id) FROM users";
DriverManager.registerDriver(new Driver());
try (final Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.100.150/test", username, password)) {
System.out.println("query = " + query);
final Stopwatch stopwatch = new Stopwatch().start();
final Statement statement = connection.createStatement();
statement.execute(query);
final ResultSet resultSet = statement.getResultSet();
while (resultSet.next()) {
System.out.println(MessageFormat.format("SUM: {0}, Count: {1}", resultSet.getLong(1), resultSet.getLong(2)));
}
resultSet.close();
statement.close();
stopwatch.stop();
System.out.println("Total time = " + stopwatch);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment