Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 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. *
  11. * @author student
  12. */
  13.  
  14. import java.sql.*;
  15. import java.util.Properties;
  16. import java.util.logging.Level;
  17. import java.util.logging.Logger;
  18.  
  19. public class Lab_JDBC {
  20.  
  21.  
  22.  
  23. /**
  24. * @param args the command line arguments
  25. */
  26. public static void main(String[] args) throws SQLException {
  27. Connection conn = null;
  28. Properties connectionProps = new Properties();
  29. connectionProps.put("user", "inf132224");
  30. connectionProps.put("password", "inf132224");
  31. try{
  32. conn = DriverManager.getConnection(
  33. "jdbc:oracle:thin:@//admlab2.cs.put.poznan.pl:1521/"
  34. + "dblab02_students.cs.put.poznan.pl",
  35. connectionProps);
  36.  
  37. }
  38. catch
  39. (SQLException ex) {
  40. Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE,"nie udało się połączyć z bazą danych", ex);
  41. System.exit(-1);
  42. }
  43. System.out.println("Połączono z DB");
  44.  
  45. Statement zad2 = null;
  46. //Statement stmt = null;
  47. //ResultSet rs = null;
  48. //ResultSet zad1 = null;
  49. ResultSet rzad2 = null;
  50. //stmt = conn.createStatement();
  51.  
  52. zad2 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  53.  
  54. // rs = stmt.executeQuery("SELECT ID_PRAC, RPAD(NAZWISKO,11), PLACA_POD FROM PRACOWNICY");
  55. /* while(rs.next()){
  56. System.out.println(rs.getInt(1)+ " "
  57. + rs.getString(2) + " " +rs.getFloat(3));
  58. }*/
  59.  
  60.  
  61. /* zad1 = stmt.executeQuery("SELECT (SELECT COUNT(NAZWISKO) FROM PRACOWNICY),COUNT(P.NAZWISKO),Z.NAZWA FROM PRACOWNICY P\n" +
  62. "JOIN ZESPOLY Z ON P.ID_ZESP = Z.ID_ZESP\n" +
  63. "GROUP BY Z.NAZWA");
  64. zad1.next();
  65. System.out.println("Zatrudniono "+ zad1.getInt(1) + "pracowników, w tym:\n");
  66. System.out.println(
  67. zad1.getInt(2) + " w zespole " +zad1.getString(3));
  68. while(zad1.next()){
  69. System.out.println(
  70. zad1.getInt(2) + " w zespole " +zad1.getString(3));
  71. }*/
  72. rzad2 = zad2.executeQuery("SELECT nazwisko from pracownicy\n" +
  73. "where etat = 'ASYSTENT'\n" +
  74. "order by placa_pod desc");
  75. rzad2.last();
  76. System.out.println(rzad2.getString(1));
  77. rzad2.previous();
  78. rzad2.previous();
  79. System.out.println(rzad2.getString(1));
  80. rzad2.first();
  81. rzad2.next();
  82. System.out.println(rzad2.getString(1));
  83.  
  84. //zad1.close();
  85. //rs.close();
  86. //stmt.close();
  87. rzad2.close();
  88. try {
  89. zad2.close();
  90. System.out.println("Rozłączono z DB");
  91. } catch (SQLException ex) {
  92. Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE, null, ex);
  93. }
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement