Advertisement
Guest User

dododo

a guest
Nov 22nd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. String nome = request.getParameter("nome");
  2. String cognome = request.getParameter("cognome");
  3. String datan = request.getParameter("data");
  4. Date data = Date.valueOf(datan);
  5. String sessoa = request.getParameter("sesso");
  6. boolean sesso = Boolean.parseBoolean(sessoa);
  7. String codiceFiscale = request.getParameter("codiceFiscale");
  8. Persona p = new Persona();
  9. p.setNome(nome);
  10. p.setCognome(cognome);
  11. p.setDataNascita(data);
  12. p.setSesso(sesso);
  13. p.setCodiceFiscale(codiceFiscale);
  14. PersonaDAO pDAO = new PersonaDAO();
  15. pDAO.inserimento(p);
  16. response.sendRedirect("Inserimento.html");
  17.  
  18.  
  19. _______________________________________________________________________________________________
  20.  
  21.  
  22. package Util;
  23.  
  24. import org.hibernate.SessionFactory;
  25. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  26. import org.hibernate.cfg.Configuration;
  27. import org.hibernate.service.ServiceRegistry;
  28.  
  29. public class HibernateUtil {
  30. private static SessionFactory sessionFactory;
  31. private static SessionFactory buildSessionFactory() {
  32. try {
  33.  
  34. Configuration configuration=new Configuration();
  35. configuration.configure();
  36. System.out.println("Hibernate Configuration loaded");
  37.  
  38. ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
  39. System.out.println("Hibernate serviceRegistry created");
  40.  
  41. SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  42.  
  43. return sessionFactory;
  44. }
  45. catch (Throwable ex) {
  46. // Make sure you log the exception, as it might be swallowed
  47. System.err.println("Initial SessionFactory creation failed." + ex);
  48. throw new ExceptionInInitializerError(ex);
  49. }
  50. }
  51.  
  52. public static SessionFactory getSessionFactory() {
  53. if(sessionFactory == null) sessionFactory=buildSessionFactory();
  54. return sessionFactory;
  55. }
  56.  
  57. }
  58. _____________________________________________________________
  59.  
  60. package Model;
  61.  
  62. import java.sql.Date;
  63.  
  64. import javax.persistence.*;
  65.  
  66. @Entity
  67. @Table(name = "Persone")
  68. public class Persona {
  69.  
  70. @Id
  71. @GeneratedValue(strategy=GenerationType.AUTO)
  72. private int ID_Persona;
  73.  
  74. @Column
  75. private String Nome;
  76. @Column
  77. private String Cognome;
  78. @Column
  79. private Date DataNascita;
  80. @Column
  81. private boolean Sesso;
  82. @Column
  83. private String CodiceFiscale;
  84.  
  85. public Persona () {}
  86.  
  87. public int getID_Persona() {
  88. return ID_Persona;
  89. }
  90.  
  91. public void setID_Persona(int iD_Persona) {
  92. ID_Persona = iD_Persona;
  93. }
  94.  
  95. public String getNome() {
  96. return Nome;
  97. }
  98.  
  99. public void setNome(String nome) {
  100. Nome = nome;
  101. }
  102.  
  103. public String getCognome() {
  104. return Cognome;
  105. }
  106.  
  107. public void setCognome(String cognome) {
  108. Cognome = cognome;
  109. }
  110.  
  111. public Date getDataNascita() {
  112. return DataNascita;
  113. }
  114.  
  115. public void setDataNascita(Date dataNascita) {
  116. DataNascita = dataNascita;
  117. }
  118.  
  119. public boolean isSesso() {
  120. return Sesso;
  121. }
  122.  
  123. public void setSesso(boolean sesso) {
  124. Sesso = sesso;
  125. }
  126.  
  127. public String getCodiceFiscale() {
  128. return CodiceFiscale;
  129. }
  130.  
  131. public void setCodiceFiscale(String codiceFiscale) {
  132. CodiceFiscale = codiceFiscale;
  133. }
  134.  
  135. @Override
  136. public String toString() {
  137. return "Persona [ID_Persona=" + ID_Persona + ", Nome=" + Nome + ", Cognome=" + Cognome + ", DataNascita="
  138. + DataNascita + ", Sesso=" + Sesso + ", CodiceFiscale=" + CodiceFiscale + "]";
  139. }
  140.  
  141.  
  142.  
  143. }
  144. ____________________________________________________________________________________
  145.  
  146.  
  147.  
  148. package Model;
  149.  
  150. import java.sql.Date;
  151.  
  152. import javax.persistence.*;
  153.  
  154. @Entity
  155. @Table(name = "Persone")
  156. public class Persona {
  157.  
  158. @Id
  159. @GeneratedValue(strategy=GenerationType.AUTO)
  160. private int ID_Persona;
  161.  
  162. @Column
  163. private String Nome;
  164. @Column
  165. private String Cognome;
  166. @Column
  167. private Date DataNascita;
  168. @Column
  169. private boolean Sesso;
  170. @Column
  171. private String CodiceFiscale;
  172.  
  173. public Persona () {}
  174.  
  175. public int getID_Persona() {
  176. return ID_Persona;
  177. }
  178.  
  179. public void setID_Persona(int iD_Persona) {
  180. ID_Persona = iD_Persona;
  181. }
  182.  
  183. public String getNome() {
  184. return Nome;
  185. }
  186.  
  187. public void setNome(String nome) {
  188. Nome = nome;
  189. }
  190.  
  191. public String getCognome() {
  192. return Cognome;
  193. }
  194.  
  195. public void setCognome(String cognome) {
  196. Cognome = cognome;
  197. }
  198.  
  199. public Date getDataNascita() {
  200. return DataNascita;
  201. }
  202.  
  203. public void setDataNascita(Date dataNascita) {
  204. DataNascita = dataNascita;
  205. }
  206.  
  207. public boolean isSesso() {
  208. return Sesso;
  209. }
  210.  
  211. public void setSesso(boolean sesso) {
  212. Sesso = sesso;
  213. }
  214.  
  215. public String getCodiceFiscale() {
  216. return CodiceFiscale;
  217. }
  218.  
  219. public void setCodiceFiscale(String codiceFiscale) {
  220. CodiceFiscale = codiceFiscale;
  221. }
  222.  
  223. @Override
  224. public String toString() {
  225. return "Persona [ID_Persona=" + ID_Persona + ", Nome=" + Nome + ", Cognome=" + Cognome + ", DataNascita="
  226. + DataNascita + ", Sesso=" + Sesso + ", CodiceFiscale=" + CodiceFiscale + "]";
  227. }
  228.  
  229.  
  230.  
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement