Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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) {
  27. Connection conn = null;
  28. Properties connectionProps = new Properties();
  29. connectionProps.put("user", "login");
  30. connectionProps.put("password", "haslo");
  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. System.out.println("Połączono z bazą danych");
  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 stmt;
  46. stmt = conn.createStatement();
  47.  
  48.  
  49.  
  50.  
  51. try {
  52. conn.close();
  53. System.out.println("Rozłączona z DB");
  54. } catch (SQLException ex) {
  55. Logger.getLogger(Lab_JDBC.class.getName()).log(Level.SEVERE, null, ex);
  56. }
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement