Results 1 to 6 of 6
  1. #1
    alvin0618 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default Java DAO create query please help

    I am not sure whether i posted this thread at the right place. Anyway my problem at below

    Java Code:
    public class Student()
          private String name;
          private String id;
          private int marks;
          private Date issueOn;
    ......
    ......
    }
    
    public class StudentDaoImpl extends HibernateDaoSupport implements StudentnDao{
               public ArrayList<Student> getSumMarkl(String dayStart, String dayEnd)throws DataAccessException{
               Session session = this.getSession();
               ArrayList<Student> stdList = new ArrayList<Student>();
               try{
                                 Query query = session.createQuery("select s.name, s.id, SUM(ms.marks) 
                                  from Student s 
                                  where TO_CHAR(TRUNC(s.issueOn),'YYYYMMDD') 
                                  between '"+dayStart+"' AND '"+dayEnd+"' 
                                  GROUP BY s.name, s.id 
                                  ORDER BY ms.id  ASC");
    .....................................................
    System.out.println("List size: " + query.list().size());
    ................................................
    // the list contains value
    //how do i get the result into my ArrayList?
    ...................................................
    .............................................
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Is Student an entity? The usual thing is to use entities and execute the query on an EntityManager that you create or lookup.

  3. #3
    alvin0618 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Is Student an entity? The usual thing is to use entities and execute the query on an EntityManager that you create or lookup.
    Yes, it is an entity. Can you more elaborate?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Elaborate which part? The key thing you are missing in your code is the EntityManager which you use to communicate with the datastore.

  5. #5
    alvin0618 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Elaborate which part? The key thing you are missing in your code is the EntityManager which you use to communicate with the datastore.
    Inside my DAO implementation, i got others methods which working fine. Something like this.getHibernateTemplate().find(query);

    But for this method, it is varies to others which need to SUM the marks from the db. The connection is connected.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    So check the documentation of your HibernateDaoSupport and HibernateTemplate to find out how to map the returned values to your DAOs. They are non-standard classes that we don't have so only their authors will be able to help you.

Similar Threads

  1. Java and appengine query?
    By Emeljats in forum New To Java
    Replies: 0
    Last Post: 12-12-2010, 10:06 PM
  2. java servlet/Query
    By KumbhaniMehul in forum Java Servlet
    Replies: 0
    Last Post: 04-06-2010, 08:19 PM
  3. Help with query (new to java!)
    By gpittingale in forum New To Java
    Replies: 3
    Last Post: 02-15-2009, 09:14 AM
  4. query on core java
    By venkatallu in forum New To Java
    Replies: 1
    Last Post: 09-01-2008, 02:23 PM
  5. Replies: 1
    Last Post: 07-24-2007, 12:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •