4 Answers
4

Preamble: I don't know scala. All code you see here is improvised from the question and a few bits of scala that I've seen somewhen. Improvements and comments are welcome

Naming:

I am going to be blunt here... Your names are bad. Not horrible, but seriously bad.

var i = ids.split(",");

first thing jumping me here is, that you have a single thing (the id-string) named with a plural. next thing that jumps me, is that you have a collection with multiple elements and it's name is a single letter.

usually the iterator in a for loop has your single letter identifier, extremely often, that is our friend i. Also you don't really have to cramop that all together. Give your variables and statements some fresh air:

for (i <- 0 to idCollection.size) {

looks much more readable IMO ;)

val result = SQL([...]

result is a dumb name. result of what? yes, I know it's the SQL statment, but if you just skim it, you could think it's what you want to return in the end.

instead I'd use dbRecord or similar.

Alright, so much for the names, now we get to the real wtf

Storing numbers:

WHY DO YOU STORE NUMBERS AS STRINGS?
AND WHY DO YOU STORE POINTS IN A SEPARATE ENTRY?pardon caps

Combine this with andrey's answer about using the IN operator to get back a Stream of results (this is Play framework, right?), then map that to another Stream and convert to a Map. Good scala practice is to use vals not vars.

Also I don't think you were building the map you wanted to build. It looks like you wanted to associate an id with a point value, but I think you ended up with a map with many ("id#" -> "someId") entries and one ("point" -> "123") that got overwritten many times and wasn't associated with any id.

You can use the Try function which is a convenient/compact alternative to writing your useful code inside try/catch (noise) block! The other salient points have been covered by earlier responses, namely using the IN clause in SQL, preferring vals over vars and pattern matching:

It seems like a good answer based on the feedback of the op, but could you elaborate a bit more ? Why would it be better to use this as opposed to the code of OP ? (You should edit your answer, and not respond to me directly in the comment).
–
Marc-AndreJun 23 '14 at 14:27