Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package lab4;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.sql.Connection;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.ArrayList;
  10. import java.util.HashSet;
  11. import java.util.Scanner;
  12.  
  13. public class Main {
  14.  
  15. public static ArrayList<Double> listOfPoints = new ArrayList<Double>();
  16.  
  17. private HashSet<Integer> loadedAreas;
  18.  
  19. static String databaseName = "baza";
  20.  
  21. public static void main(String[] args) throws SQLException, FileNotFoundException{
  22.  
  23. DBAdapter db = new DBAdapter(databaseName);
  24.  
  25. File file = new File("C:\\Users\\student\\Desktop\\mc-4_lab_mc_10\\dane_politechnika.txt");
  26.  
  27.  
  28. Statement st = db.connection.createStatement();
  29. st.execute("CREATE TABLE IF NOT EXISTS coords (id INTEGER PRIMARY KEY AUTOINCREMENT, x REAL, y REAL, h REAL);");
  30.  
  31.  
  32. Scanner scanner = new Scanner(file);
  33. while(scanner.hasNextDouble()){
  34. listOfPoints.add(scanner.nextDouble());
  35. //System.out.println(l.get(l.size() - 1));
  36. }
  37.  
  38. AwtControlDemo c = new AwtControlDemo();
  39. c.showCanvasDemo();
  40.  
  41. for(int i = 0; i < listOfPoints.size(); i+=3)
  42. {
  43. // st.execute("INSERT INTO coords (x, y, h) VALUES (" + l.get(i) + "," + l.get(i+1) + "," + l.get(i+2) + ");");
  44. }
  45.  
  46. ResultSet rset = st.executeQuery("SELECT * FROM coords;");
  47.  
  48. int rowCount = 0;
  49. while(rset.next()) { // Move the cursor to the next row, return false if no more row
  50. double x = rset.getDouble("x");
  51. double y = rset.getDouble("y");
  52. double h = rset.getDouble("h");
  53. System.out.println(x + ", " + y + ", " + h);
  54. ++rowCount;
  55. }
  56.  
  57. st.close();
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement