Created
August 22, 2012 03:31
-
-
Save jordansjones/3422081 to your computer and use it in GitHub Desktop.
Test Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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