tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Laffey <...@laffeycomputer.com>
Subject Re: Confusing Problem with SQL Query in Tomcat
Date Tue, 27 Mar 2001 06:07:44 GMT
On Mon, 26 Mar 2001, Hunter Hillegas wrote:
> >
> >>             pst.clearParameters();
> >
> >
> > No need for clearParameters(). The setString will override any old
> > parameters (if their were any).
>
> Can't hurt though, can it?

Don't think so, but why make extra method calls ;-)

> >
> > My guess is that it has something to do with the
> > rs.getString(java.lang.String) call. Try rs.getString(int) instead to
> > narrow it down. (The int is the column number. I would highly suggest
> > doing something like "SELECT name, column2, column3, FROM <table> WHERE
> > <whereclause>" instead of doing "SELECT * ...". If all you want is the
> > name then only SELECT that.
>
> You think? The counter isn't getting incremented at all, suggesting that
> rs.next() is evaluating to false, thus suggesting the query is returning 0
> rows...

Hmmm... My bad. I should have read that part of your note more carefully.
Now I am a little confused...

You tried pasting a plain SELECT string with no "?"s in the
prepareStatement string? Are you certain that the connection pool works
right? Try it with a plain connection that you establish right there in
the code perhaps.

What happens when there is more than one row in the DB that matches your
WHERE clause? Then does it work? if so, is it mssing one row, or complete?

Is it possible that you have a non-committed transaction from a command
line client that is holding up this SELECT with a lock? (It should give an
exception.) Do you not see an exception? If not, are you sure your
exception reporting code works right?

Here is an interesting quote from the Sun docs on ResultSet:

" The column name option is designed to be used when column names are used
in the SQL query. For columns that are NOT explicitly named in the query,
it is best to use column numbers. If column names were used there is no
way for the programmer to guarantee that they actually refer to the
intended columns."

This might explain not being able to get the data, but it doesn't seems to
explain why the rs.next() would be false.


>
> Do column numbers start at 0 or 1? I will try changing the query and using
> the column number...
>

For some reason they start at 1. Note that this should be faster than the
string anyway.



Joe Laffey
LAFFEY Computer Imaging
St. Louis, MO
----------------------
Need to do multi-file string replacement in Un*x, but don't want to mess
with sed? Try rpl. It's a free text replacement utility with source.
http://www.laffeycomputer.com/rpl.html  -- Check it out!
------------------------------------------------------------------------




Mime
View raw message