Java gets the last value of sequences in Oracle

Source: Internet
Author: User

Project, use a sequence as a single number, the framework is used by SSH, when the DAO layer to fetch, run times wrong to dual is not  mapped,[select *.nextval nextvalue from dual]
Later, the inspection found that the way to get the wrong, so change to the following, you can normally get
    //get the last value of a SEQ     PublicString findseq () {         Try{String SQL= "Select Patient_seq.nextvalNextValueFrom dual "; Integer Maxid= (Integer) ( This. GetSession (). createsqlquery (SQL). Addscalar ("NextValue", Hibernate.integer)).                  Uniqueresult (); returnmaxid.tostring (); } Catch(Exception e) {e.printstacktrace (); }              return NULL; }

If you have integrated Hibernatedaosupport, you can also use the following method:

 Public String findseq () {        nextvalue from dual ";
return (String) Gethibernatetemplate (). Find (QueryString). Get (0);
}
1. First return to list collection gethibernatetemplate (). Find (QueryString)
2. Get the first element of list: List.get (0);
The result of 3.list.get (*) is ojbect, so either a strong-turn (String) list.get (0), or list.get (0). toString ();

Java gets the last value of sequences in Oracle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.