Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String nome = request.getParameter("nome");
- String cognome = request.getParameter("cognome");
- String datan = request.getParameter("data");
- Date data = Date.valueOf(datan);
- String sessoa = request.getParameter("sesso");
- boolean sesso = Boolean.parseBoolean(sessoa);
- String codiceFiscale = request.getParameter("codiceFiscale");
- Persona p = new Persona();
- p.setNome(nome);
- p.setCognome(cognome);
- p.setDataNascita(data);
- p.setSesso(sesso);
- p.setCodiceFiscale(codiceFiscale);
- PersonaDAO pDAO = new PersonaDAO();
- pDAO.inserimento(p);
- response.sendRedirect("Inserimento.html");
- _______________________________________________________________________________________________
- package Util;
- import org.hibernate.SessionFactory;
- import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
- import org.hibernate.cfg.Configuration;
- import org.hibernate.service.ServiceRegistry;
- public class HibernateUtil {
- private static SessionFactory sessionFactory;
- private static SessionFactory buildSessionFactory() {
- try {
- Configuration configuration=new Configuration();
- configuration.configure();
- System.out.println("Hibernate Configuration loaded");
- ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
- System.out.println("Hibernate serviceRegistry created");
- SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
- return sessionFactory;
- }
- catch (Throwable ex) {
- // Make sure you log the exception, as it might be swallowed
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- if(sessionFactory == null) sessionFactory=buildSessionFactory();
- return sessionFactory;
- }
- }
- _____________________________________________________________
- package Model;
- import java.sql.Date;
- import javax.persistence.*;
- @Entity
- @Table(name = "Persone")
- public class Persona {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private int ID_Persona;
- @Column
- private String Nome;
- @Column
- private String Cognome;
- @Column
- private Date DataNascita;
- @Column
- private boolean Sesso;
- @Column
- private String CodiceFiscale;
- public Persona () {}
- public int getID_Persona() {
- return ID_Persona;
- }
- public void setID_Persona(int iD_Persona) {
- ID_Persona = iD_Persona;
- }
- public String getNome() {
- return Nome;
- }
- public void setNome(String nome) {
- Nome = nome;
- }
- public String getCognome() {
- return Cognome;
- }
- public void setCognome(String cognome) {
- Cognome = cognome;
- }
- public Date getDataNascita() {
- return DataNascita;
- }
- public void setDataNascita(Date dataNascita) {
- DataNascita = dataNascita;
- }
- public boolean isSesso() {
- return Sesso;
- }
- public void setSesso(boolean sesso) {
- Sesso = sesso;
- }
- public String getCodiceFiscale() {
- return CodiceFiscale;
- }
- public void setCodiceFiscale(String codiceFiscale) {
- CodiceFiscale = codiceFiscale;
- }
- @Override
- public String toString() {
- return "Persona [ID_Persona=" + ID_Persona + ", Nome=" + Nome + ", Cognome=" + Cognome + ", DataNascita="
- + DataNascita + ", Sesso=" + Sesso + ", CodiceFiscale=" + CodiceFiscale + "]";
- }
- }
- ____________________________________________________________________________________
- package Model;
- import java.sql.Date;
- import javax.persistence.*;
- @Entity
- @Table(name = "Persone")
- public class Persona {
- @Id
- @GeneratedValue(strategy=GenerationType.AUTO)
- private int ID_Persona;
- @Column
- private String Nome;
- @Column
- private String Cognome;
- @Column
- private Date DataNascita;
- @Column
- private boolean Sesso;
- @Column
- private String CodiceFiscale;
- public Persona () {}
- public int getID_Persona() {
- return ID_Persona;
- }
- public void setID_Persona(int iD_Persona) {
- ID_Persona = iD_Persona;
- }
- public String getNome() {
- return Nome;
- }
- public void setNome(String nome) {
- Nome = nome;
- }
- public String getCognome() {
- return Cognome;
- }
- public void setCognome(String cognome) {
- Cognome = cognome;
- }
- public Date getDataNascita() {
- return DataNascita;
- }
- public void setDataNascita(Date dataNascita) {
- DataNascita = dataNascita;
- }
- public boolean isSesso() {
- return Sesso;
- }
- public void setSesso(boolean sesso) {
- Sesso = sesso;
- }
- public String getCodiceFiscale() {
- return CodiceFiscale;
- }
- public void setCodiceFiscale(String codiceFiscale) {
- CodiceFiscale = codiceFiscale;
- }
- @Override
- public String toString() {
- return "Persona [ID_Persona=" + ID_Persona + ", Nome=" + Nome + ", Cognome=" + Cognome + ", DataNascita="
- + DataNascita + ", Sesso=" + Sesso + ", CodiceFiscale=" + CodiceFiscale + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement