Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static void addUsers(Connection connection, int count, int minLength, int maxLength) throws SQLException {
- Statement statement = connection.createStatement();
- usersIDList = new ArrayList<Integer>(count);
- for (int index = 0; index < count; index++) {
- final String username = RandomStringUtils.randomAlphabetic(new Random().nextInt(maxLength - minLength) + minLength) + index;
- final String password = RandomStringUtils.randomAlphabetic(20);
- final String info = RandomStringUtils.randomAlphabetic(20);
- final String pathpic = RandomStringUtils.randomAlphabetic(20);
- statement.executeUpdate(String.format("INSERT INTO users (login, password, info, path_pic) VALUES (\'%s\',\'%s\',\'%s\',\'%s\');", username, password, info, pathpic));
- ResultSet res = statement.executeQuery("SELECT lastval();");
- res.next();
- int userID = res.getInt(1);
- usersIDList.add(userID);
- }
- statement.close();
- }
- private static void addSubscriptions(Connection connection, int minCount, int maxCount) throws SQLException {
- Statement statement = connection.createStatement();
- for (int id : usersIDList) {
- final int count = new Random().nextInt(maxCount - minCount) + minCount + 1;
- for (int i = 0; i < count; i++) {
- if (id == usersIDList.get(i)) {
- continue;
- }
- statement.executeUpdate(String.format("INSERT INTO subscriptions (subscriber_id, to_user_id) VALUES (%d, %d);", id, usersIDList.get(i)));
- }
- }
- statement.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement