I've played with java quite a bit but am new to JSP's
I want to put this code in my JSP to retieve some data from a MySQL database
if I run this code in a stand alone jave app it works fine
when I put it in a JSP it returns an empty ResultSet even though it should be getting data
no error, it just doesn't return the data it should
is there something different about JSP's I'm missing
I realize I could just put the code in a bean or a servlet and the problem would go away, I just want to understand what's going on
[ January 05, 2007: Message edited by: Dave Robbins ]
Apart from all the architectural clap-trap I could pile upon you, as you can see, it makes it hard to debug when things go awry.
Rather, factor all your database access out into a normal java class that you can test from a standalone command-line application. Once that is working, it should be easy to call (not move) the code from your JSP, or better yet, a servlet controller that you use to keep all code out of JSPs.
it just doesn't return any data
if I uncomment the "//Object o = rs.getString(0);" line it will throw an exception and say I've run off the end of the rowset
I know I should move the code out of the jsp but I want to know why it's failing
The ResultSet interface provides getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.
It looks like you are indexing from zero instead of 1.
Originally posted by Dave Robbins:
you're correct, but it doesn't explain why it's coming back with no data
I've converted it to using a bean and it works fine
I assume you've got the database calls wrapped in a set of try/catch blocks.
What are you doing when an exception is thrown?
What's in your catch block?
[ January 08, 2007: Message edited by: Paul Clapham ]