- import java.lang.reflect.Array;
- import java.sql.*;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- public class Main {
- private static final String INSERT_USERS_SQL = "INSERT INTO users"+ " (username, email, category) VALUES " + "(?,?,?);";
- public static void main(String str[]) throws SQLException {
- Connection connection = null;
- String url = "jdbc:postgresql://localhost:5432/vacuum_db";
- String name= "postgres";
- String p = "723982";
- try{
- Class.forName("org.postgresql.Driver");
- connection = DriverManager.getConnection(url, name,p);
- } catch (ClassNotFoundException | SQLException e) {
- throw new RuntimeException(e);
- }
- List<String> names = new ArrayList<>(Arrays.asList("Даниил","Марина","Максим","Дарья","Владислав","Екатерина","Никита","Александра","Артем","Алиса","Иван","Владислава","Кирилл","Карина","Егор","Елена","Илья","Виктория","Андрей","София","Максим","Герман","Анна","Алена","Станислав","Мирон","Тимофей","Платон","Родион"));
- List<String> mail = new ArrayList<>(Arrays.asList("@bk.ru","@mail.ru","@gmail.com","@yandex.ru","@rambler.ru","@inbox.ru","@list.ru","@internet.ru","@yahoo.com","@hotmail.com","@outlook.com"));
- Random r = new Random();
- final String INSERT_USERS_SQL = "INSERT INTO users"+ " (username, email, category) VALUES " + "(?,?,?);";
- PreparedStatement statement = connection.prepareStatement(INSERT_USERS_SQL);
- for (int i=0;i<=999999;i++){
- int ran1 = r.nextInt(0,28);
- System.out.println(names.get(ran1));
- String emailAddress ="";
- String alphabet ="abcdefghijklmnopqrstuvwxyz";
- while (emailAddress.length()<5){
- int character = (int) (Math.random() *26);
- emailAddress += alphabet.substring(character,character+1);
- }
- int ran2=r.nextInt(0,9);
- emailAddress +=Integer.valueOf((int) (Math.random()*1000)).toString()+mail.get(ran2);
- statement.setString(1, names.get(ran1));
- statement.setString(2,emailAddress);
- statement.setString(3,"FOO");
- statement.execute();
- System.out.println(emailAddress);
- }
- }
- }
[text] test1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- test1
- Paste Code
- 20 Mar-2023
- 2.49 Kb
You can Share it:
Latest Code Pastes