First of all, I need to point out that your code is showing some very bad practices. Putting
Java code in a JSP, especially database code, is a practice that has been discredited for 10 years now, since 2002! It's far past time to update your JSP knowledge with the JSTL and JSP.
What you are asking is a common requirement and you can search for previous questions on this subject.
As you are using jQuery, you can even get some free sample code by downloading the example code for my book for free
here. Look for the "bootcloset" folder in the code for chapter 8.