Ramesh, first of all JSP isn't place to write your application logic. It is considered as bad practice.
Regarding your exception problem -
You can't be absolutely sure of which exception your JSP is throwing. You'll always get java.lang.SQLException in every case as you are explicitly throwing it from your code. Try to print the stack trace to get the exact exception.