I have PostgreSQL db and I use JDBC to connect and generate table, but I want to generate table with random data. so I create java methods which generate random names and surnames which I want to set into my table into special columns (name, surname). My db :
DROP TABLE IF EXISTS groups;
CREATE TABLE groups(
name VARCHAR(50),
surname VARCHAR(50),
);
and I try to set name and surname using this code:
String URL = "jdbc:postgresql://localhost:5432/school";
String user = "principal";
String password = "123";
String sqlScript = new String(Files.readAllBytes(Path.of("src/main/resources/database/dbScript.sql")));
Connection connection = DriverManager.getConnection(URL, user, password);
System.out.println("Success.........");
Statement script = connection.createStatement();
script.execute(sqlScript);
//class with random gen.
StudentsGenerator generator = new StudentsGenerator();
String query1 = "INSERT INTO groups " +"VALUES (generator.student().stream().map(names -> names.getName()))";
script.executeUpdate(query1);