Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Dao;
- import java.sql.*;
- import model.Persone;
- public class DaoPersone {
- static Connection conn; //attributo statico per la connesione
- public static void apriConnessione () {
- try { Class.forName("oracle.jdbc.driver.OracleDriver");
- conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "System", "scemenza");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- //metodo per chiudere la connesione con il database
- public void chiudiConnessione () {
- try {conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void inserisciLettore (Persone l){
- PreparedStatement ps;
- String query ="Insert into Lettori (NOME,COGNOME,EMAIL,TELEFONO,ETA,CODICELETTORE) VALUES (?,?,?,?,?,?)";
- apriConnessione () ;
- try {
- ps =(PreparedStatement) conn.prepareStatement(query);
- ps.setString(1, l.getNome());
- ps.setString(2, l.getCognome());
- ps.setString(3, l.getEmail());
- ps.setInt (4, l.getEta());
- ps.setString (5, l.getCodice_lettore());
- }
- catch (SQLException e ) {
- e.printStackTrace();
- }
- chiudiConnessione();
- }
- }
- //uajo o programm s pav
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement