String query = ("insert into complaint(name,issue,whenadded)
VALUES('$name','$issue',now())" );
This is my query.i am using strut-hibernate. how to execute the above query ?
String query = ("insert into complaint(name,issue,whenadded)
VALUES('$name','$issue',now())" );
This is my query.i am using strut-hibernate. how to execute the above query ?
Telling from your question you are very new to Hibernate. Hibernate will automatically insert any entity objects which have been modified during the current session. So to carry out your INSERT
in Hibernate, you can create a Complaint
POJO, assign the three fields you want, and then save the session.
Complaint complaint = new Complaint();
stockTran.setName("A complaint");
stockTran.setIssue("Hibernate SO question");
stockTran.setWhenAdded(new Date());
session.save(complaint);
Using Hibernate you can save a whole object, you don't need to fire insert into xyz values(x,x) query. If you use it, then Hibernate is worthless. But you must have to do mapping of table with POJO (complaint) via XML or annotation configuration.
You should write this code snap:
Session session = sessionFactory.openSession();
Complaint complaintObject = new Complaint();
complaintObject.setName(<Name_of_complaint>);
complaintObject.setIssue(<issue_detail>);
complaintObject.setWhenAdded(new Date());
session.beginTransaction();
session.save(complaint);
session.getTransaction().commit();
Regarding timezone issue :
public static Date convertLocalToISTTimezone( Date localDate )
{
Date datetoReturn = null;
try
{
setLog("*%" + "On " + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()) + " GMT **** ENTER :" + localDate);
TimeZone timezone = TimeZone.getTimeZone('<set_timezone_where _your server_will_be>');
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
sdf.setTimeZone(timezone);
SimpleDateFormat sdfgmt = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT+05:30");
sdfgmt.setTimeZone(gmtTimeZone);
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
datetoReturn = dateFormatLocal.parse(sdfgmt.format(sdf.parse(sdf.format(localDate))));
setLog("*%" + "On " + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()) + " GMT **** EXIT :" + datetoReturn);
}
catch ( ParseException e )
{
e.printStackTrace();
}
return datetoReturn;
}