Well, I'm sure you know that I'm going to tell you that putting
Java code into a JSP, especially database access, is a really bad practice that causes lots of problems, including ones like this.
My advice: move the Java code into Java classes, and use the JSTL and EL on the page rather than obsolete and discredited scriptlets.