• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

hql problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi to all,

List result = session1.createQuery("select l.username , l.password from Login AS l ").list();

this is my query and now i have to take username and password from the result, then what code should i write there?


thanks in advance

yogesh
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in your login table, you'll have something like:


id userName PassWord
1 "A" 123
2 "B" 456
3 "C" 1z9


your List result contains arrays:
("A", 123), ("B", 456), etc

i guess you can code like this:

hope this helps
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi yogesh

Here is an example and think this should clear your doubt:--

The example is as follows

public MessageDataBO addOutgoingMessage(MessageDataBO msgData)
{
Session session=null;
int arr_cnt = 0;
try
{
Configuration config = new Configuration().configure();
config.addClass(MessageDataBO.class);
SessionFactory sessionFactory = config.buildSessionFactory();
session = sessionFactory.openSession();

Query query = session.createQuery("from MessageDataBO");
System.err.println("Executing HQL " + query.getQueryString());

try {
int count = 0;
List list = query.list();
if (null != list){
Iterator i=list.iterator();

String str_mess [][] = new String [list.size()][7];
while(i.hasNext())
{
msgData = ((MessageDataBO)i.next());
str_mess[arr_cnt][0] = msgData.getIdGroup();
str_mess[arr_cnt][2] = msgData.getDateTime().toString();
str_mess[arr_cnt][5] = msgData.getMessage();
arr_cnt++;
}

System.err.println("The query returned " + list.size() + " rows");
this.str_mess = str_mess;
}
else {
System.err.println("The result of the query was null");
}

} catch (Exception e1){
System.err.println("Exception " + e1.getMessage());
e1.printStackTrace();
}

}
catch(HibernateException he)
{
System.out.println("Hibernate Exception :"+he.getLocalizedMessage());
he.printStackTrace();
}

finally
{
if (session != null)
{
try
{
session.close();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
}
}
return msgData;
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic