Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JDBC and MS Access

  Asked By: Sienna    Date: Sep 18    Category: Java    Views: 931

I have a question regarding how java sorts vs how access sorts.

If I take the following three values: 4" 4' 47"

and sort ascending in access I get 4" 4' 47"
but if I sort them in jdbc using the following sql statement

SELECT Abbreviation,Description FROM [Abbreviation List] ORDER BY

I get 4' 4" 47" which logically seems correct.

I am trying to write a comparator class to use in Arrays.binarysearch
and am having trouble finding values that do exist. I am checking
each character in a lexicon order system, does this seem correct?



2 Answers Found

Answer #1    Answered By: Darrell Harvey     Answered On: Sep 18

Are you trying to sort  "inches" and "feet"?

If so, you need to cast both objects in your comparrison to a
String. Then, use a <string>.indexOf("\"") to find where the " is or
a <string>.indexOf("\'"); to find where the ' is.

Then, you can use a substring method to extract the numeric and
the "measurement type" from the string.

Now, you can convert each number to an int and multiply the ints
which represent "feet" by 12 to normalize all the metrics. Now, you
can actually compare the two values.

This seems like a lot of work, but it really isn't. And once you
write it, you don't have to do it again.

Answer #2    Answered By: Bethany Hughes     Answered On: Sep 18

The inches and feet symbol are only part of
the complete resultset that I need to get. What I decided to do was
to keep the Binary search as I have it set up and get results that
way. If the search doesn't find a value then I run through the list
of objects found in the result set one at a time. Because of the
sorting differences the binary search finds the proper value about
90% of the time, so the extra time searching after the fact does not
add alot.

I like your idea though, and may try it out down the road if this
project turns into something more. It would require writing a method
to sort  the values  after I get them from SQL rather than letting SQL
sort them up front.

Didn't find what you were looking for? Find more on JDBC and MS Access Or get search suggestion and latest updates.