Java version result set row inverted __java

Source: Internet
Author: User
Tags getdate

The data obtained from the database is generally returned in an entity manner. But to make a statement, it may be from the entity of a property to show that the so-called column inversion. So someone wrote a list of inverted SQL, and here's a Java implementation example. Attributes are written to death. If you need to be flexible, replace it with reflection to traverse the property.

/** * The list information ranks inverted */package jdk_1_4.test; Import java.util.ArrayList; Import java.util.Collections; Import Java.util.Comparator; Import Java.util.Iterator; Import Java.util.LinkedHashMap; Import java.util.LinkedList; Import java.util.List; Import Java.util.Map; public class V2htest {/** * @param args */public static void main (string[] args) {List dataList = new ArrayList (); setd ATA (DataList, "1"); SetData (DataList, "2"); --Sort Collections.sort by date and brand (DataList, new Comparator () {public int compare (object O1, Object O2) {Datamodel dm1 = (Da Tamodel) O1; Datamodel dm2 = (datamodel) O2; int flag = Dm1.getdate (). CompareTo (Dm2.getdate ()); if (flag = = 0) {flag = Dm1.gettobacconame (). CompareTo (Dm2.gettobacconame ());} return flag; } }); /**/System.out.println ("--------------------------------------before the rank and column conversion"); for (int i=0;i<datalist.size (); i++) {datamodel dm = (datamodel) datalist.get (i); System.out.println ("Date:" +dm.getdate ()); System.out.println ("Cigarette:" +dm.gettobacconame ()); System.out.prIntln (Dm.getdate () + "Day production Plan:" +dm.getproduceqty ()); System.out.println (Dm.getdate () + "Day sales Plan:" +dm.getsaleqty ()); System.out.println (Dm.getdate () + "Daily Minimum inventory line:" +dm.getinvlinelow ()); System.out.println (Dm.getdate () + "Day of the highest inventory line:" +dm.getinvlinehigh ()); System.out.println (Dm.getdate () + "Day at the end of inventory:" +dm.getinventoryqty ()); SYSTEM.OUT.PRINTLN ("----"); //--row inversion Map v2hmap = new Linkedhashmap (); V2hmap = v2h (datalist,6); Object[] Tobaccoarr = (object[]) v2hmap.get ("Tobacco"); System.out.println ("--------------------------------------/n" After the order of rows); System.out.println ("-------cigarette brand"); System.out.print (""); for (int i=0;i<tobaccoarr.length;i++) {System.out.print (tobaccoarr[i]+ "");} System.out.println (); V2hmap.remove ("Tobacco"); /**/Iterator it = V2hmap.keyset (). iterator (); while (It.hasnext ()) {String key = It.next (). toString ();//system.out.println (key);/**/LinkedList hlist = (linkedlist) v 2hmap.get (key); for (int i=0;i

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.