Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. package zad1;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Database {
  6.  
  7. String url;
  8. String username = "s14245";
  9. String password = "oracle12";
  10. Connection con = null;
  11.  
  12. public Database(String url, TravelData travelData) {
  13.  
  14. this.url=url;
  15. }
  16.  
  17. public void create() {
  18.  
  19. System.out.println("ŁĄCZENIE Z BAZĄ DANYCH...");
  20. //polaczenie z baza danych Oracle
  21. try{
  22. //sterownik
  23. Class.forName("oracle.jdbc.driver.OracleDriver");
  24. System.out.println("Sterowniki załadowane");
  25.  
  26. //polaczenie z baza
  27. con = DriverManager.getConnection(url, username, password);
  28. System.out.println("Połączenie nawiązane");
  29.  
  30. }catch (ClassNotFoundException exc) { // brak klasy sterownika
  31. System.out.println("Brak klasy sterownika");
  32. System.out.println(exc);
  33. System.exit(1);
  34. }catch(SQLException exc) { // nieudane połączenie
  35. System.out.println("Nieudane połączenie z " + url);
  36. System.out.println(exc);
  37. System.exit(1);
  38. }
  39. /*
  40. //zapytanie do bazy
  41. String query = "SELECT * FROM EMP";
  42. Statement statement;
  43. try {
  44. statement = con.createStatement();
  45. ResultSet rs = statement.executeQuery(query);
  46. //wypisywanie z tabeli
  47. while(rs.next()){
  48. try{
  49. String daneZBazy = rs.getString(1);
  50. System.out.println("\n" + daneZBazy + " ");
  51. daneZBazy = rs.getString(2);
  52. System.out.println(daneZBazy + " ");
  53. daneZBazy = rs.getString(3);
  54. System.out.println(daneZBazy);
  55. daneZBazy = rs.getString(4);
  56. System.out.println(daneZBazy);
  57. }catch(SQLException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. } catch (SQLException e1) {
  62. e1.printStackTrace();
  63. }
  64. */
  65. }
  66.  
  67. public void showGui() {
  68.  
  69.  
  70. }
  71.  
  72. }
  73. package zad1;
  74.  
  75. import java.io.*;
  76. import java.util.*;
  77.  
  78.  
  79.  
  80. public class TravelData {
  81.  
  82. String adres_pliku = "data/oferty.txt";
  83. String loc, kraj, miejsce, symbol_waluty;
  84. double cena;
  85. String data_wyjazdu, data_powrotu;
  86.  
  87. public TravelData(File dataDir) {
  88.  
  89. dataDir = new File(adres_pliku);
  90.  
  91. // ODCZYT PLIKU .TXT
  92.  
  93. String linia;
  94. BufferedReader bfr = null;
  95. try {
  96. bfr = new BufferedReader(new FileReader(dataDir));
  97. } catch (FileNotFoundException e1) {
  98. e1.printStackTrace();
  99. }
  100. // ODCZYT KOLEJNYCH LINII Z PLIKU:
  101. try {
  102. while((linia = bfr.readLine()) != null){
  103. System.out.println(linia);
  104. }
  105. } catch (IOException e) {
  106. System.out.println("BŁĄD ODCZYTU Z PLIKU!");
  107. System.exit(2);
  108. }
  109.  
  110. }
  111.  
  112.  
  113. public List<String> getOffersDescriptionsList(String locale, String dateFormat) {
  114.  
  115.  
  116. return null;
  117. }
  118.  
  119.  
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement