insert java.sql.Timestamp data in oracle timestamp(6) column using Hibernate -
i want insert line in table called vol
in oracle database using struts2 form insert action returns "input"
, don't execute insertion vol.java
code:
package models; import java.sql.timestamp; import java.util.date; import javax.persistence.entity; import javax.persistence.id; import javax.persistence.table; import javax.persistence.temporal; import javax.persistence.temporaltype; @entity @table(name="vol") public class vol { @id private int idvol; private string typeavion; private string nomavion; private string depart; private string destination; @temporal(temporaltype.timestamp) private date heuredepart; private string heurearrivee; private string technicien; public int getidvol() { return idvol; } public void setidvol(int idvol) { this.idvol = idvol; } public string gettypeavion() { return typeavion; } public void settypeavion(string typeavion) { this.typeavion = typeavion; } public string getnomavion() { return nomavion; } public void setnomavion(string nomavion) { this.nomavion = nomavion; } public string getdepart() { return depart; } public void setdepart(string depart) { this.depart = depart; } public string getdestination() { return destination; } public void setdestination(string destination) { this.destination = destination; } public date getheuredepart() { return heuredepart; } public void setheuredepart(date heuredepart) { this.heuredepart = heuredepart; } public string getheurearrivee() { return heurearrivee; } public void setheurearrivee(string heurearrivee) { this.heurearrivee = heurearrivee; } public string gettechnicien() { return technicien; } public void settechnicien(string technicien) { this.technicien = technicien; } public vol(){ } }
this code of form:
<s:form action="ajoutvol" method="post"> <s:textfield name="vol.idvol" label="idvol" size="20" /> <s:textfield name="vol.typeavion" label="type avion" size="20" /> <s:textfield name="vol.nomavion" label="nom avion" size="20" /> <s:textfield name="vol.depart" label="depart" size="20" /> <s:textfield name="vol.destination" label="destination" size="20" /> <s:textfield name="heuredepart" label="heure de dapart" size="20" /> <s:textfield name="vol.heurearrivee" label="heure d'arrivée" size="20" /> <s:textfield name="vol.technicien" label="technicien" size="20" /> <s:submit name="submit" label="submit" /> </s:form>
this execute method of action:
public string execute(){ voldao vd= new voldao(); simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss"); try { vol.setheuredepart(dateformat.parse(heuredepart)); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } vd.insertvol(vol); map session = actioncontext.getcontext().getsession(); session.put("vol", vol); return success; }
and code of method insertvol()
:
public void insertvol(vol vol){ sessionfactory sessionfactory=new annotationconfiguration().configure().buildsessionfactory(); session session=sessionfactory.opensession(); session.begintransaction(); session.save(vol); session.gettransaction().commit(); session.close(); sessionfactory.close(); }
use following code insert timestamp
data timestamp
oracle type
vol.setheuredepart(new timestamp(dateformat.parse(heuredepart).gettime()));
the entity should map column like
@column(name = "heure_depart", length = 19) private date heuredepart;
Comments
Post a Comment