Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by kovac on 18/02/2017.
- */
- import java.sql.*;
- import java.io.*;
- import java.util.Scanner;
- public class permutacie_vybav {
- public static void main(String[] args) throws FileNotFoundException {
- Connection con = null;
- Statement st = null;
- String url = "jdbc:postgresql://192.168.99.100:32775/dbs_project";
- String user = "xkovaca_user";
- String password = "johmv123";
- //FILLING
- int id_vybav = 1;
- String nazov_vybavy;
- String farba;
- String typ_laku;
- try {
- con = DriverManager.getConnection(url, user, password);
- //st = con.createStatement();
- PreparedStatement ps = con.prepareStatement("INSERT INTO individualne_vybavy (id, nazov_vybavy, farba, typ_laku) VALUES (?, ?, ?, ?)");
- File file = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\vybava.txt");
- Scanner sc = new Scanner(file);
- while(sc.hasNextLine()){
- nazov_vybavy = sc.nextLine();
- File file_pohon = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\farba.txt");
- Scanner sc_pohon = new Scanner(file_pohon);
- while(sc_pohon.hasNextLine()) {
- farba = sc_pohon.nextLine();
- File file_vykon = new File("C:\\Users\\kovac\\Documents\\School\\2 SEMESTER\\DBS\\data_db\\vybava\\typ_laku.txt");
- Scanner sc_vykon = new Scanner(file_vykon);
- while (sc_vykon.hasNextLine()) {
- typ_laku = sc_vykon.nextLine();
- ps.setInt(1, id_vybav);
- ps.setString(2, nazov_vybavy);
- ps.setString(3, farba);
- ps.setString(4, typ_laku);
- ps.addBatch();
- id_vybav++;
- }
- int[] results = ps.executeBatch();
- }
- //System.out.println(sc.nextLine());
- }
- } catch (SQLException ex) {
- } finally {
- try {
- if (st != null) {
- st.close();
- }
- if (con != null) {
- con.close();
- }
- } catch (SQLException ex) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement