During project development today, the column names returned by database queries are incorrectly ordered. The query statement is select ID and name from info_user. In principle, the returned column order should be ID, name, however, the returned data is name and ID due to the no-order of hashmap. In this case, I overwrite the handlerow method of maplisthandler.CodeThe backup is as follows:
Public ClassLinkmaplisthandler extends maplisthandler {@ overrideProtectedMap <string, Object> handlerow (resultset RS) throws sqlexception {Map <string, Object> result =NewLinkedhashmap <string, Object> (); resultsetmetadata rsmd = Rs. getmetadata ();IntCols = rsmd. getcolumncount ();For(IntI = 1; I <= Cols; I ++) {result. Put (rsmd. getcolumnname (I), RS. GetObject (I ));}ReturnResult ;}}
Call Statement:
List = (list <Map <string, Object>) queryrunner. Query (SQL,NewLinkmaplisthandler (),Params);
Simple and Convenient...