Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. /**
  2.  * Created by kovac on 18/02/2017.
  3.  */
  4. import java.sql.*;
  5. import java.io.*;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class permutacie_vybav {
  10.  
  11.     public static void main(String[] args) throws FileNotFoundException {
  12.  
  13.         Connection con = null;
  14.         Statement st = null;
  15.  
  16.         String url = "jdbc:postgresql://192.168.99.100:32775/dbs_project";
  17.         String user = "xkovaca_user";
  18.         String password = "johmv123";
  19.  
  20.  
  21.         //FILLING
  22.         int id_vybav = 1;
  23.         String nazov_vybavy;
  24.         String farba;
  25.         String typ_laku;
  26.  
  27.  
  28.         try {
  29.  
  30.             con = DriverManager.getConnection(url, user, password);
  31.  
  32.  
  33.             //st = con.createStatement();
  34.             PreparedStatement ps = con.prepareStatement("INSERT INTO individualne_vybavy (id, nazov_vybavy, farba, typ_laku) VALUES (?, ?, ?, ?)");
  35.  
  36.             File file = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\vybava.txt");
  37.             Scanner sc = new Scanner(file);
  38.  
  39.             while(sc.hasNextLine()){
  40.  
  41.                 nazov_vybavy = sc.nextLine();
  42.  
  43.                 File file_pohon = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\farba.txt");
  44.                 Scanner sc_pohon = new Scanner(file_pohon);
  45.  
  46.                 while(sc_pohon.hasNextLine()) {
  47.  
  48.                     farba = sc_pohon.nextLine();
  49.  
  50.                     File file_vykon = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\typ_laku.txt");
  51.                     Scanner sc_vykon = new Scanner(file_vykon);
  52.  
  53.                     while (sc_vykon.hasNextLine()) {
  54.  
  55.                         typ_laku = sc_vykon.nextLine();
  56.  
  57.                         ps.setInt(1, id_vybav);
  58.                         ps.setString(2, nazov_vybavy);
  59.                         ps.setString(3, farba);
  60.                         ps.setString(4, typ_laku);
  61.                         ps.addBatch();
  62.                        
  63.                         id_vybav++;
  64.                     }
  65.                     int[] results = ps.executeBatch();
  66.                 }
  67.  
  68.                 //System.out.println(sc.nextLine());
  69.             }
  70.  
  71.  
  72.  
  73.         } catch (SQLException ex) {
  74.  
  75.  
  76.         } finally {
  77.  
  78.             try {
  79.                 if (st != null) {
  80.                     st.close();
  81.                 }
  82.                 if (con != null) {
  83.                     con.close();
  84.                 }
  85.  
  86.             } catch (SQLException ex) {
  87.  
  88.             }
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement