Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lab_jdbc;
  7.  
  8. /**
  9. *
  10. * @author student
  11. */
  12.  
  13. import java.sql.*;
  14. import java.util.Properties;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. public class Lab_JDBC {
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. public static void main(String[] args) throws SQLException {
  23. //KONEKT
  24. Connection conn = null;
  25. Properties connectionProps = new Properties();
  26. connectionProps.put("user", "inf127273");
  27. connectionProps.put("password", "inf127273");
  28. try {
  29. conn = DriverManager.getConnection("jdbc:oracle:thin:@//admlab2.cs.put.poznan.pl:1521/"
  30. + "dblab02_students.cs.put.poznan.pl",connectionProps);
  31. System.out.println("Połączono z bazą danych");
  32. } catch (SQLException ex) {
  33. Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE,
  34. "nie udało się połączyć z bazą danych", ex);
  35. System.exit(-1);
  36. }
  37. //DEKLARACJA STEJTMENT DO BAZY DANYCH
  38. Statement stmt = null;
  39. ResultSet rs = null; //RESULT wynik
  40. try {
  41. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
  42. ResultSet.CONCUR_READ_ONLY);
  43. rs = stmt.executeQuery("SELECT COUNT(nazwisko) FROM pracownicy");
  44. while (rs.next()) {
  45. System.out.println(rs.getInt(1) + " " );
  46. }
  47. } catch (SQLException ex) {
  48. System.out.println("Bład wykonania polecenia" + ex.toString());
  49. }
  50. rs.close();//zamknij cztytacz
  51. rs = stmt.executeQuery("SELECT nazwisko,placa_pod FROM pracownicy where etat = 'ASYSTENT'"
  52. + "order by placa_pod DESC");
  53. while (rs.next()) {
  54. System.out.println(rs.getString(1) + " "+rs.getFloat(2));
  55. }
  56. rs.last();
  57. for (int i = 0; i < 2; i++) {
  58. rs.previous();
  59. }
  60. System.out.println(rs.getString(1));
  61. rs.close();
  62.  
  63. stmt.close(); //zamknij stejtment
  64.  
  65. //DISKONEKT
  66. try {
  67. conn.close();
  68. } catch (SQLException ex) {
  69. Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE, null, ex);
  70. }
  71. System.out.println("DISKONEKT");
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement