tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hunter Hillegas <>
Subject Confusing Problem with SQL Query in Tomcat
Date Tue, 27 Mar 2001 04:32:42 GMT
I have a strange problem with my Servlet app running in Tomcat 3.2.1 on

The method posted below takes a String and uses it in conjunction with a
PreparedStatement to create a query. I've added debugging code to the method
to print output to the screen to help me but I can't figure it out.

Basically the query is returning nothing.

When I run the query from the SQL command line (PostgreSQL 7.1) it returns
one row.

When I substitute the actual String in the query instead of using setString,
it doesn't work. I'm kind of baffled...

The counter I have set for debugging returns 0 and the output of the String
that's brought into the method matches the one I use in the query that runs
properly on the command line. Any help would be appreciated.

I do all sorts of DB access in other parts of my app and it works just fine.


Here is the method:

    private boolean artistExists (HttpServletRequest request,
HttpServletResponse response, String artistName) throws IOException,
ServletException {
        Connection con = null;
        PreparedStatement pst = null;
        ResultSet rs = null;
        boolean artistExists = false;
        PrintWriter out = response.getWriter();
        out.println("Input Artist Name: " + artistName + "<BR>");
        int counter = 0;
        //END DEBUG
        try {
            con = myBroker.getConnection();
            pst = con.prepareStatement("SELECT * FROM artist_info WHERE
upper(name) = upper(?)");
            pst.setString(1, artistName);
            rs = pst.executeQuery();
            while ( {
                out.println("Is the inputted name: " + artistName + " equal
to: " + rs.getString("name") + "?<BR>"); //DEBUG
                counter++; //DEBUG
                if (artistName.equalsIgnoreCase(rs.getString("name"))) {
                    artistExists = true;
            Integer theInteger = new Integer(counter); //DEBUG
            String theCounter = theInteger.toString(); //DEBUG
            out.println("Counter: " + theCounter); //DEBUG
        catch (Exception e) {
            request.setAttribute("javax.servlet.jsp.jspException", e);
            RequestDispatcher rd =
            rd.forward(request, response);
        //return true; //DEBUG
        return artistExists;

View raw message