Advertisement
Guest User

Untitled

a guest
May 10th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package main;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.HashSet;
  9. import java.util.Random;
  10. import java.util.Scanner;
  11.  
  12. public class DatabaseInsert {
  13.     Random rand = new Random();
  14.     public DatabaseInsert() throws SQLException{
  15.        
  16.         try {
  17.  
  18.         Class.forName("org.postgresql.Driver");
  19.  
  20.         } catch (ClassNotFoundException e) {
  21.             e.printStackTrace();
  22.  
  23.         }
  24.          
  25.         Connection connection = null;
  26.  
  27.         try {
  28.  
  29.         connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/cinemator", "postgres", "admin");
  30.  
  31.         } catch (SQLException e) {
  32.  
  33.         System.out.println("Connection Failed! Check output console");
  34.         e.printStackTrace();
  35.         return;
  36.  
  37.         }
  38.          
  39.         Statement stmt = connection.createStatement();
  40.         int i = 1, c;
  41.         int id;
  42.         String meno;
  43.         String heslo;
  44.         String rarity;
  45.         int j = 1;
  46.        
  47.         int k = 1;
  48.         int z;
  49.         Random r = new Random();
  50.         Scanner sc = new Scanner(System.in);
  51.         while (i < 100) {
  52.             while ( j < 25) {
  53.                 k = 1;
  54.                 if (r.nextInt(2) == 1) {
  55.                     k = 1;
  56.                     z = 4;
  57.                 }
  58.                 else {
  59.                     k = 5;
  60.                     z = 9;
  61.                 }
  62.                 while (k < z) {
  63.             System.out.print("meno ");
  64.             int hod = r.nextInt(3)+3;
  65.             /*System.out.print("rola ");
  66.            
  67.             int rola = sc.nextInt();
  68.             String opis = "fasa";
  69.             System.out.print("pohlavie ");
  70.             String pohlavie = sc.next();*/
  71.             String sql = String.format("INSERT INTO oblubeny VALUES ('%d','%d','%d');", i, j, k);
  72.             stmt.executeUpdate(sql);
  73.             k++;
  74.             i++;
  75.                 }
  76.             j++;
  77.             }
  78.            
  79.         }
  80.         }
  81.        
  82.         public static void main(String[] args) throws SQLException {
  83.             new DatabaseInsert();
  84.         }
  85.    
  86.    
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement