| Author |
Danish Sorting with core java and sorting through SQL.
|
Mohan Karthick
Ranch Hand
Joined: Apr 11, 2005
Posts: 199
|
|
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.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
First of all, you need to Use Code Tags. You can edit your post to add them.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Mohan Karthick
Ranch Hand
Joined: Apr 11, 2005
Posts: 199
|
|
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.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
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.
|
 |
 |
|
|
subject: Danish Sorting with core java and sorting through SQL.
|
|
|