Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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 inf122419;
  7.  
  8. /**
  9. *
  10. * @author student
  11. */
  12. import java.sql.*;
  13. import java.util.Properties;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16.  
  17. public class Inf122419 {
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. public static void main(String[] args) {
  23. Connection conn = null;
  24. Properties connectionProps = new Properties();
  25. connectionProps.put("user", "inf122419");
  26. connectionProps.put("password", "inf122419");
  27.  
  28. try {
  29. conn = DriverManager.getConnection("jdbc:oracle:thin:@//admlab2.cs.put.poznan.pl:1521/dblab02_students.cs.put.poznan.pl", connectionProps);
  30. conn.setAutoCommit(false);
  31. System.out.println("Połączono z bazą danych");
  32. } catch (SQLException ex) {
  33. Logger.getLogger(Inf122419.class.getName()).log(Level.SEVERE,
  34. "nie udało się połączyć z bazą danych", ex);
  35. System.exit(-1);
  36. }
  37.  
  38. Statement stmt = null;
  39. ResultSet rs = null;
  40.  
  41. try {
  42. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
  43. ResultSet.CONCUR_READ_ONLY);
  44. rs = stmt.executeQuery("select nazwisko " + "from pracownicy " + "where etat='ASYSTENT' order by placa_pod DESC");
  45. rs.last();
  46. System.out.println("Asystent zarabiający najmniej " + rs.getString(1));
  47.  
  48.  
  49. } catch (SQLException ex) {
  50. System.out.println("Bład wykonania polecenia" + ex.toString());
  51. } finally {
  52. if (rs != null) {
  53. try {
  54. rs.close();
  55. } catch (SQLException e) {
  56. /* kod obsługi */ }
  57. }
  58. if (stmt != null) {
  59. try {
  60. stmt.close();
  61. } catch (SQLException e) {
  62. /* kod obsługi */ }
  63. }
  64. }
  65.  
  66. try {
  67. conn.close();
  68. } catch (SQLException ex) {
  69. Logger.getLogger(Inf122419.class.getName()).log(Level.SEVERE, null, ex);
  70. }
  71. System.out.println("Odłączono z bazą danych");
  72.  
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement