• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Danish Sorting with core java and sorting through SQL.

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have to do Danish language based sorting for the records coming from DB

In SQL we are giving default sorting which is based on Danish NLS

E.g. select * from tablename ORDER by NLSSORT(code, 'NLS_SORT=danish') which is coming proper



In UI we have screen which accepts these sorting given done above SQL .User can click on the header of the column of table (where all the records are populated)

To do the sorting and we need sorting based on same Danish nls so in UI we are using Collator to sort according to Danish language the sample code is as below :


import java.text.*;

import java.util.*;

class Cricket {



public static void main(String[] args) {

String[] names = { "Ab", "@", "cc","AA", "dd", "DD", "e", "1","2", "!","Æ","å","z"};

List list = Arrays.asList(names);

Collections.sort(list);

Iterator itr = list.iterator();

while (itr.hasNext()) {

System.out.print(itr.next() + " ");

}

Locale[] loc = Collator.getAvailableLocales();

Collator myCollator = Collator.getInstance(new Locale("da"));

myCollator.setStrength(Collator.SECONDARY);

Collections.sort(list, myCollator);

//Collections.sort(list);

itr = list.iterator();

System.out.println(""+ Collator.getAvailableLocales());

while (itr.hasNext()) {

System.out.print(itr.next() + " ");

}

//myCollator.setStrength(Collator.TERTIARY);

Collections.sort(list, myCollator);

itr = list.iterator();

System.out.println("");

while (itr.hasNext()) {

System.out.print(itr.next() + " ");

}

}

}


But the problem is, retreived result from above two are different i.e from SQL and Core Java, please advice what needs to be done.
 
Sheriff
Posts: 22780
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, you need to Use Code Tags. You can edit your post to add them.
 
Mohan Karthick
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have to do Danish language based sorting for the records coming from DB

In SQL we are giving default sorting which is based on Danish NLS

E.g. select * from tablename ORDER by NLSSORT(code, 'NLS_SORT=danish') which is coming proper



In UI we have screen which accepts these sorting given done above SQL .User can click on the header of the column of table (where all the records are populated)

To do the sorting and we need sorting based on same Danish nls so in UI we are using Collator to sort according to Danish language the sample code is as below :


But the problem is, retreived result from above two are different i.e from SQL and Core Java, please advice what needs to be done.

I am resubmitting the problem with code tag.


 
Marshal
Posts: 28140
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This article -- Supported Locales -- says that Danish is supported by Java 6. But it also says that the locale ID is "da_DK" which suggests to me that

might work better than the locale you are using. That's just a guess, though.
 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic