Solved

howto catch SQL exception in jsp subroutine

Posted on 2011-09-08
4
563 Views
Last Modified: 2012-05-12
I have the function shown below in a jsp program. When I try to  run the page I get the error:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 255 in the jsp file: /printVouchers.jsp
sqe cannot be resolved

This very same code works fine as a function in a java program, What's wrong?

<%!
static boolean printDROPinfo(Connection con, JspWriter out, String memberId) throws Exception
{
    ResultSet rs = null;
    Statement stmt = con.createStatement();
    String query = "";

    query = "select ... from ... where ...";

    try {
        rs = stmt.executeQuery(query);
    }
    catch ( SQLException sqe) {
      // do some things
    }

    rs.close();
   return true;
}
0
Comment
Question by:jmarkfoley
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 250 total points
ID: 36505320
for the beginning try to change
catch ( SQLException sqe)

to

catch ( Exception sqe)

It probably would not help but could give some clue
0
 
LVL 3

Assisted Solution

by:evedder
evedder earned 250 total points
ID: 36505494
maybe silly question but did you include the SQLException class in the jsp?
0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 36507690
Well, I just recoded the function from scratch and it works! The new code looks exactly like the code fragment I posted. Dunno, I must have messed up something. Thanks - points for the participation.
0
 
LVL 1

Author Closing Comment

by:jmarkfoley
ID: 36507696
recoded and worked. No idea why.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question