Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package Dao;
  2. import java.sql.*;
  3. import model.Persone;
  4. public class DaoPersone {
  5. static Connection conn; //attributo statico per la connesione
  6. public static void apriConnessione () {
  7. try { Class.forName("oracle.jdbc.driver.OracleDriver");
  8. conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "System", "scemenza");
  9. } catch (ClassNotFoundException e) {
  10. e.printStackTrace();
  11. } catch (SQLException e) {
  12. e.printStackTrace();
  13. }
  14. }
  15. //metodo per chiudere la connesione con il database
  16. public void chiudiConnessione () {
  17. try {conn.close();
  18. } catch (SQLException e) {
  19. e.printStackTrace();
  20. }
  21. }
  22. public void inserisciLettore (Persone l){
  23. PreparedStatement ps;
  24. String query ="Insert into Lettori (NOME,COGNOME,EMAIL,TELEFONO,ETA,CODICELETTORE) VALUES (?,?,?,?,?,?)";
  25. apriConnessione () ;
  26. try {
  27. ps =(PreparedStatement) conn.prepareStatement(query);
  28. ps.setString(1, l.getNome());
  29. ps.setString(2, l.getCognome());
  30. ps.setString(3, l.getEmail());
  31. ps.setInt (4, l.getEta());
  32. ps.setString (5, l.getCodice_lettore());
  33. }
  34. catch (SQLException e ) {
  35. e.printStackTrace();
  36. }
  37. chiudiConnessione();
  38. }
  39. }
  40. //uajo o programm s pav
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement