Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.Random;
- import java.util.Scanner;
- public class DatabaseInsert {
- Random rand = new Random();
- public DatabaseInsert() throws SQLException{
- try {
- Class.forName("org.postgresql.Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Connection connection = null;
- try {
- connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cinemator", "postgres", "admin");
- } catch (SQLException e) {
- System.out.println("Connection Failed! Check output console");
- e.printStackTrace();
- return;
- }
- Statement stmt = connection.createStatement();
- int i = 1, c;
- int id;
- String meno;
- String heslo;
- String rarity;
- int j = 1;
- int k = 1;
- int z;
- Random r = new Random();
- Scanner sc = new Scanner(System.in);
- while (i < 100) {
- while ( j < 25) {
- k = 1;
- if (r.nextInt(2) == 1) {
- k = 1;
- z = 4;
- }
- else {
- k = 5;
- z = 9;
- }
- while (k < z) {
- System.out.print("meno ");
- int hod = r.nextInt(3)+3;
- /*System.out.print("rola ");
- int rola = sc.nextInt();
- String opis = "fasa";
- System.out.print("pohlavie ");
- String pohlavie = sc.next();*/
- String sql = String.format("INSERT INTO oblubeny VALUES ('%d','%d','%d');", i, j, k);
- stmt.executeUpdate(sql);
- k++;
- i++;
- }
- j++;
- }
- }
- }
- public static void main(String[] args) throws SQLException {
- new DatabaseInsert();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement