-->
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: returning selected fields from table
PostPosted: Tue Oct 24, 2006 3:33 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
hi,

how can access the selected fields returned from a query ?

eg.

sql_str = "select distinct v.name, v.title from Vendor as v"
Query query = session.createQuery(sql_str);
list = (ArrayList) query.list();

how do i use java code to extract name and title from the list ?

thanks.

Hibernate version: 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 3:53 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Code:
String queryString = "select distinct v.name, v.title from Vendor as v"
Query query = session.createQuery(queryString);
List list =  query.list();

Iterator resultsIterator = list.iterator();

while (resultsIterator.hasNext()) {

Object [] objects = (Object[]) resultsIterator.next();

//assuming that v.name and v.title are of type java.lang.String
String name = (String) objects[0];

String title = (String) objects[1];


} //end of while


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.