Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- public class H2 {
- private static final String FILLER = "ABCDEFGHIJKLMNOPRSTUWYZabcdefghijklmnoprstuwyz1234567890";
- private static final int NUMBER_OF_INSERTIONS = 100000;
- /**
- * @param args
- * @throws SQLException
- */
- public static void main(final String[] args) throws SQLException {
- // final Connection connection =
- // DriverManager.getConnection("jdbc:h2:db/TEST;DB_CLOSE_ON_EXIT=TRUE",
- // "sa", null);
- final Connection connection = DriverManager.getConnection(
- "jdbc:h2:tcp://localhost/~/test", "sa", null);
- connection.createStatement().executeUpdate("DROP TABLE IF EXISTS data");
- connection
- .createStatement()
- .executeUpdate(
- "CREATE TABLE `data` (`id` IDENTITY NOT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `name` varchar(128) DEFAULT NULL,`author` varchar(128) DEFAULT NULL, `notes` varchar(128) DEFAULT NULL);");
- final PreparedStatement preparedStatement = connection
- .prepareStatement("INSERT INTO data (name, author, notes) VALUES(?,?,?)");
- int numberOfInsertions = NUMBER_OF_INSERTIONS;
- final long startTime = System.currentTimeMillis();
- while (numberOfInsertions-- > 0) {
- preparedStatement.setString(1, FILLER);
- preparedStatement.setString(2, FILLER);
- preparedStatement.setString(3, FILLER);
- preparedStatement.executeUpdate();
- }
- final long stopTime = System.currentTimeMillis();
- final long deltaSeconds = (stopTime - startTime) / 1000L;
- preparedStatement.close();
- connection.close();
- System.out.println(NUMBER_OF_INSERTIONS / deltaSeconds + "/s");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement