Forums Register Login

sorting in Chinese

+Pie Number of slices to send: Send
I am trying to sort list of chinese countries (for example) but the order does not come out right. Here is a sample of my code. I am connecting to the database and using select to get list of strings (Countries). Take these list and sort it using a Collator with Chinese Locale (I tried olso the new Locale("zh","CN")).
Please assist!
Thanks!!
Here is my code:
-------------------------------------------------------------------
import java.text.*;
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

public class Sort {
public static void main(String s[]) {
Vector list = connectToDB();

Collator collate = Collator.getInstance(Locale.SIMPLIFIED_CHINESE);
collate.setDecomposition(Collator.FULL_DECOMPOSITION);
collate.setStrength(Collator.SECONDARY);
Collections.sort(list, collate);
StringBuffer result = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
result.append(list.elementAt(i));
result.append(" "); //$NON-NLS-1$
}
System.out.println("\nPrint After Sorting:"); // Print col 1
System.out.println(result.toString());

}

private static Vector connectToDB() {
Vector list = new Vector();
try {

Connection con = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc racle:thin:@ORACLE-TESTVM:1521 ratest", "GROUPAMA_28_08", "GROUPAMA_28_08");
Statement s = con.createStatement();


ResultSet rset = s.executeQuery("select RESOURCE_VALUE from t_resources where resource_lang = 'zh' and resource_code in \n" +
"(select distinct dsc_id from T_COUNTRY)");
System.out.println("Print Before Sorting:"); // Print col 1
while (rset.next()) {
list.add(rset.getString(1));
System.out.println(rset.getString(1)); // Print col 1
}

System.out.println("\n*********************\nEnd of Print Before Sorting:"); // Print col 1
s.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1221 times.
Similar Threads
java.io.notserializable Exception HELP
Can't Get This toString Method Overridden. Why?
Danish Sorting with core java and sorting through SQL.
Best way to handle huge write operation
question about locale
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:08:43.