-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: updating timestamp with now(), mysql database and Hibernate
PostPosted: Mon Oct 06, 2008 12:17 am 
Newbie

Joined: Mon Oct 06, 2008 12:12 am
Posts: 2
I tried to use
public boolean updateLastLog(String email)
{
boolean action = true;

Session session = HibernateUtil.getSession();



try{
session.createSQLQuery("update userProfile set LASTLOG=now() where US_EMAIL = '"+email+"'");
session.flush();

}catch (GenericJDBCException gje) {
action = false;
log.error(methodNM +gje.getMessage() +" 1catch "+gje.getSQLState());
System.out.println(methodNM +gje.getMessage() +" 1catch "+gje.getSQLState());
}catch (SQLGrammarException e){
action = false;
log.error(methodNM +" 2catch "+e.toString());
System.out.println(methodNM +" 2catch "+e.toString());
}finally{
HibernateUtil.closeSession();
}
return action;
}

this does not seem to work


if I want to use Hibernate my guess would be to do:

update UserProfile set lastLog = :XXX where usEmail = : email.

but I do not know what value goes where XXX

can anyone give me a good direction how to update timestamp using hql

Thank you


Top
 Profile  
 
 Post subject: solution
PostPosted: Mon Oct 06, 2008 1:11 am 
Newbie

Joined: Mon Oct 06, 2008 12:12 am
Posts: 2
public boolean updateLastLog(String email){
methodNM = CLASS_NAME+" updateLastLog";
log.info("in..."+methodNM);
boolean action = true;

Session session = HibernateUtil.getSession();
Date time = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String now = sdf.format(time);
System.out.println(now);

try{
String hqlQuery = "update UserProfile set lastlog = :now where usEmail = :email";
Query query = session.createQuery(hqlQuery);
query.setString("now", now);
query.setString("email", email);
query.executeUpdate();
session.flush();
}catch (Exception e) {
log.error(methodNM + e.toString());
System.out.println(methodNM + e.toString());
action = false;
return action;
}finally{
HibernateUtil.closeSession();
}
return action;
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.