SHARE
TWEET

asd

a guest Mar 20th, 2016 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package data;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7. import java.sql.PreparedStatement;
  8. import javax.faces.bean.ManagedBean;
  9. import javax.faces.bean.RequestScoped;
  10. import javax.faces.event.ActionEvent;
  11. import javax.servlet.jsp.jstl.sql.Result;
  12. import javax.servlet.jsp.jstl.sql.ResultSupport;
  13.  
  14. @ManagedBean(name = "bazaBean")
  15. @RequestScoped
  16. public class Baza {
  17.     private Result osoby = null;
  18.     private Osoba osoba;
  19.     private Connection conn;
  20.  
  21.     public Baza() {
  22.         try {
  23.             DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());
  24.             conn = DriverManager.getConnection(
  25.                     "jdbc:db2://5.10.125.192:50000/SQLDB:retrieveMessagesFromServerOnGetMessage=true;",
  26.                     "user05433",
  27.                     "ErbX4eSSonU4");
  28.         } catch (Exception e) {
  29.             int a = 10;
  30.             int b = a+2;
  31.             // throw;
  32.         }
  33.     }
  34.  
  35.     public Result getOsoby() {
  36.         try {
  37.             Statement stmt = conn.createStatement();
  38.             ResultSet rset = stmt.executeQuery("SELECT * FROM USER05433.OSOBA");
  39.             osoby = ResultSupport.toResult(rset);
  40.             stmt.close();
  41.         } catch (Exception e) {
  42.         }
  43.         return osoby;
  44.     }
  45.  
  46.     public void saveOsoba(Osoba osoba) {
  47.         try {
  48.             PreparedStatement stmt = conn.prepareStatement("INSERT INTO OSOBA (IMIE, NAZWISKO, PESEL) VALUES (?,?, ?)");
  49.             stmt.setString(1, osoba.getImie());
  50.             stmt.setString(2, osoba.getNazwisko());
  51.             stmt.setString(3, osoba.getPesel());
  52.             stmt.executeUpdate();
  53.             stmt.close();
  54.         } catch (Exception e) {
  55.         }
  56.         return;
  57.     }
  58.  
  59.     public void deleteOsoba(String pesel) {
  60.         try {
  61.             PreparedStatement stmt = conn.prepareStatement("DELETE FROM OSOBA WHERE PESEL = ?");
  62.             stmt.setString(1, pesel);
  63.             stmt.executeUpdate();
  64.             stmt.close();
  65.         } catch (Exception e) {
  66.         }
  67.         return;
  68.     }
  69.        
  70.    
  71.     public Osoba loadOsobaByPesel (String pesel1) {
  72.         try {
  73.         PreparedStatement stmt = conn.prepareStatement("SELECT * FROM OSOBA WHERE PESEL = ? ");
  74.         stmt.setString(1, pesel1);
  75.         ResultSet rset = stmt.executeQuery ();
  76.         osoba = new Osoba() ;
  77.         while (rset.next()) {
  78.         osoba.setNazwisko ( rset.getString("NAZWISKO") ) ;
  79.         osoba.setImie ( rset.getString("IMIE") ) ;
  80.         osoba.setPesel ( rset.getString("PESEL") ) ;
  81.         }
  82.         stmt.close() ;
  83.         } catch (Exception e) {}
  84.         return osoba ;
  85.         }
  86.    
  87.     public void updateOsoba (Osoba osoba) {
  88.         try {
  89.         PreparedStatement stmt = conn.prepareStatement("UPDATE OSOBA SET IMIE = ?, NAZWISKO = ?  WHERE PESEL = ?");
  90.         stmt.setString(1, osoba.getImie());
  91.         stmt.setString(2, osoba.getNazwisko());
  92.         stmt.setString(3, osoba.getPesel());
  93.         stmt.executeUpdate();
  94.         stmt.close() ;
  95.         } catch (Exception e) {}
  96.         return  ;
  97.         }
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top