-->
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: Manipulate SQLQuery results
PostPosted: Wed Aug 01, 2012 9:06 am 
Newbie

Joined: Wed Aug 01, 2012 5:51 am
Posts: 8
Hi !

According to my browsing, getting the results from a SQLQuery should look like this :
Code:
         session = HibernateUtil.currentSession();

         String query = "SELECT num_loc FROM Circulation";
         
         List<Object[]> rows = (List<Object[]>)session.createSQLQuery(query)
         .addScalar("num_loc", Hibernate.STRING)
         .list();
         
         System.out.println(rows.size());
         
         for (Object[] row : rows){
            System.out.print(row[0]);
         }

But I get an error when it comes to the "row[0]". Do you where I'm doing wrong ? I'm using Hibernate 3 by the way !

Thanks in advance !


Top
 Profile  
 
 Post subject: Re: Manipulate SQLQuery results
PostPosted: Mon Aug 06, 2012 4:32 am 
Newbie

Joined: Wed Aug 01, 2012 5:51 am
Posts: 8
For those who may have the same question, this works fine in my program :
Code:
      try {
         session = HibernateUtil.currentSession();

         String num = "XXXX";

         String sql_query = "SELECT C.Id, C.num_loc, A.Lieux FROM Circulation C, Appro_gasoil A WHERE C.num_loc = num";
         
         @SuppressWarnings("unchecked")
         Query query = session.createSQLQuery(sql_query)
         .addScalar("Id", Hibernate.INTEGER)
         .addScalar("num_loc", Hibernate.STRING)
         .addScalar("Lieux", Hibernate.STRING);
         
         List result = (List)query.list();
         
         for(int i=0; i<result.size(); i++) {
            Object[] ligne = (Object[])result.get(i);
            System.out.println(ligne[2]);
         }
      
      } catch (HibernateException e) {
         System.out.println("Erreur dans la requĂȘte concernant les approvisionnements en gasoil");
         e.printStackTrace();
      }


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.