Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class BazaDanych{
  8.  
  9. public static void main(String[] args) throws SQLException {
  10.  
  11. Statement statement = null;
  12. Connection connection = null;
  13.  
  14. try {
  15. Class.forName("org.postgresql.Driver");
  16.  
  17. // "jdbc:postgresql://nazwahosta:port/
  18. // nazwabazy","uzytkownik", "haslo"
  19. connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/patryk","patryk", "zadanieap");
  20.  
  21. // String selectTableSQL = "SELECT * FROM spis;";
  22. // statement = connection.createStatement();
  23. //
  24. // System.out.println(selectTableSQL);
  25. //
  26. // // wykonywanie SQL
  27. // ResultSet rs = statement.executeQuery(selectTableSQL);
  28. //
  29. // while (rs.next()) {
  30. //
  31. // String id = rs.getString("Id");
  32. // String imie = rs.getString("Imie");
  33. // String nazwisko = rs.getString("Nazwisko");
  34. // String pesel = rs.getString("PESEL");
  35. // String data_ur = rs.getString("Data_urodzenia");
  36. // String plec = rs.getString("Plec");
  37. // String obyw = rs.getString("Obywatelstwo");
  38. // String zarobki = rs.getString("zarobki");
  39. //
  40. // System.out.println("Id: " + id);
  41. // System.out.println("Imie: " + imie);
  42. // System.out.println("Nazwisko: " + nazwisko);
  43. // System.out.println("PESEL: " + pesel);
  44. // System.out.println("Data urodzenia: " + data_ur);
  45. // System.out.println("Płeć: : " + plec);
  46. // System.out.println("Obywatelstwo: : " + obyw);
  47. // System.out.println("Zarobki: : " + zarobki);
  48. //
  49. //
  50. // }
  51. } catch (ClassNotFoundException e) {
  52.  
  53. e.printStackTrace();
  54. System.out.append("Nie masz sterownika");
  55. }
  56. catch (SQLException e )
  57. {
  58. e.printStackTrace();
  59. System.out.append("Zle dane");
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement