SquirreL SQL does that. Works really well too.
I guess for JSP pages you could add something like this to get the current cursor index:
<script type = "text/javascript">
function showCursorPos(myField){
if (myField.selectionStart || myField.selectionStart == '0') {
alert('Cursor is on index ' + myField.selectionStart);
}else{
alert('dunno');
}
}
</script>
<form name = "myform">
<textarea name = "txtQuery" rows = "10" cols = "50">Blah blah, fishpaste</textarea>
<br><br>
<input type ="button" value="Get Cursor Index" onclick="showCursorPos(document.myform.txtQuery )">
</form>
You can then search backward until you either reach the beginning or an empty line and use that as the start index, and search forward until you either reach the end or an empty line as the end index. If the browser doesn't support the syntax, just use the current behaviour.
I quickly tested this and it gave me the correct index using Chrome, IE and Firefox.