-->
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: can i run "select now()" ? (mysql)
PostPosted: Mon Mar 20, 2006 1:40 pm 
Newbie

Joined: Fri Jan 16, 2004 9:32 am
Posts: 11
Hibernate version: 2.1

Name and version of the database you are using: MySQL 3.x

How do I execute queries that don't involve objects? For example, I want to execute "select now()" in MySQL to get the current db timestamp. The documentation talks about native sql queries, but they still involve objects.

Thanks
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 20, 2006 2:40 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
try:
<sql-query name="getTS">
<return-scalar column="DT" type="java.sql.Timestamp"/>
select now() as dt
</sql-query>

Then in your java code call w/ something like:
Query q = sess.getNamedQuery("getTS");
Object obj=q.uniqueResult();
if(obj instanceof Long)
{
System.out.println("answer:" + ((java.sql.Timestamp)obj).toString());
}

//or you can loop through the results with:
Iterator itr=q.list().iterator();
while(itr!=null&&itr.hasNext())
{
obj=itr.next();
System.out.println("answer:" + ((java.sql.Timestamp)obj).toString());
}

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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.