If you can think of a way that the question might possibly be salvageable, then you should definitely edit the post and make it so. For questions like this, that are on the verge of closure or deletion for being of such poor quality, I don't even think it's terribly important how close you stay to the author's intent. If you can transform their useless question into one that others might find useful, you've done the community at large a great service. Hopefully, they'll learn something from your edits and start asking better questions in the future. That way, everyone is benefited.
If you can't think of any way to improve the post (and by that I mean substantively improve the post, not simply "turd-polishing", as Jeff is fond of calling it), then vote to close as "Not A Real Question" (or some other possibly-relevant reason). If you don't yet have close vote privileges, then flag away.
The site is just too large and gets too many questions per minute to waste much time fretting over a few questions that could be good, but just aren't. The "close" button has become a pretty big target for me recently, and I don't shed even one tear for those questions.
Now, if the problem lies not so much with the question, but rather with the asker's misguided understanding of technologies, I'd say that changes things a little. If it seems likely that the misunderstanding could be corrected (and thus the question fixed) through a brief exchange in the comments, then you should strongly consider leaving such a comment.
If that doesn't appear to be possible (i.e., their misunderstanding is far too gross and/or once that misunderstanding is cleared up, the question doesn't even make sense to ask), then you should post your attempt at clarification as an answer to the question. Because it does, in fact, answer the question. You deserve to get some rep for this, and others who come along with the same question will hopefully learn something from your explanation. I answer a lot of questions with answers like "No, no, you've got this all wrong. Let me see if I can't explain it a little better..." and those seem to get upvotes. Sometimes, if I'm lucky, they even get accepted. Learning something is the point here. How to Ask even tells us this:
Keep an open mind
The answer to your question may not always be the one you wanted, but that doesn’t mean it is wrong. A conclusive answer isn’t always possible. When in doubt, ask people to cite their sources, or to explain how/where they learned something. Even if we don’t agree with you, or tell you exactly what you wanted to hear, remember – we’re just trying to help.
So, for your specific example, I think it would be perfectly reasonable to answer this question with an explanation that details how Java and SQL can be used to solve this problem, or even render this "problem" a non-issue.