-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to get nextval from a sequence
PostPosted: Thu Nov 04, 2004 8:38 am 
Newbie

Joined: Tue Aug 24, 2004 6:43 am
Posts: 3
Hi all,
I have a problem getting nextval form a sequence in Postgres.

I'd like execute the simple SQL code:

select nextval('<my_sequence_in_postgres>')

and return the int value of the nextval of teh sequence.

Could anybody help me?

Thanks and regards,

Andrea

_________________
--- Andrea Fontanelli --


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 8:43 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Guess chapter 9.3.6. Queries in native SQL of the reference manual is for you.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 04, 2004 9:31 am 
Newbie

Joined: Tue Aug 24, 2004 6:43 am
Posts: 3
ernst_pluess wrote:
Guess chapter 9.3.6. Queries in native SQL of the reference manual is for you.

HTH
Ernst


HI,
thanks for your answer. I already tryed thi way, but I got thi Exception:

class java.lang.UnsupportedOperationException

this is my source code:

log.debug(session.createSQLQuery("select nextval('contacts_userid_seq')", "", Integer.class).getQueryString());

query = session.createSQLQuery("select nextval('contacts_userid_seq')", "", Integer.class);

Integer nextValue = (Integer)query.iterate().next();

log.debug("Next Value= " + nextValue.intValue());

Why I have this exception?

Something to configure?

Andrea

_________________
--- Andrea Fontanelli --


Top
 Profile  
 
 Post subject: An example doing what you're trying
PostPosted: Tue Nov 16, 2004 2:59 pm 
Newbie

Joined: Tue Nov 16, 2004 2:57 pm
Posts: 1
Here is how I did that:

Code:
            Connection conn = sess.connection();
           
            Statement stmt = conn.createStatement();
            ResultSet res = stmt.executeQuery("select genid_seq_standard.nextval from dual");
            if (res.next())
            {
                nextId = res.getString(1);
            }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 4:43 pm 
Newbie

Joined: Tue Aug 24, 2004 6:43 am
Posts: 3
Thank you.
I followed the same way:

conn = HibernateUtil.currentSession().connection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select nextval('"+ ApplicationResource.CONTACT_SEQ + "')");
rs.next();
Integer nextVal = new Integer(rs.getString(1));

Ciao,
andrea

_________________
--- Andrea Fontanelli --


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.