Forums Register Login

Problem with executeQuery

+Pie Number of slices to send: Send
I have a simple code where I'm having problem with executeQuery:



Strange thing is, when I copy the exact query from here to MySQL query browser, a result set is returned. I get database connection established message (code not showing here) and I do not get any exception. But I get r = 0 does not matter what.

Another thing is, just for checking when I used executeUpdate with an INSERT command it does insert the data into the database. What could be the reason INSERT is working but SELECT is not?
+Pie Number of slices to send: Send
Hi Tokai,
I've also tried using the same api to get the number of rows returned, but it did not work. The driver might be using optimising techniques to get the results as the result set might be huge and the query might take a lot of time to execute. it be better to have a count of rows returned as well and check that column to get the fetch size. i'm sure if you iterate over the result set you'd see that there are results returned for the query.
+Pie Number of slices to send: Send
No the result set is actually empty. It in the example I was doing, it returns 2 results when executed the query from query browser, and returns zero results when executed from the code. I would say that was a problem with connection, but then how come INSERT works?
+Pie Number of slices to send: Send
First of all that code will throw a NullPointerException because you don't have any code that executes a query. But let's suppose your actual code has that code not commented out. The next line of code doesn't tell you the number of records that would be in the ResultSet if you read them all, it tells you the fetch size of the ResultSet. That is a number that you can set to tell the server how many records to return at a time, it has nothing to do with the number of actual records.

So if that is what you base "returns zero results" on, don't do that. Read through the ResultSet and see what you get.
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 916 times.
Similar Threads
reusing the Statement object
why it is not compiling
multiple processes... only want one
PreparedStatement problem
stored procedures in a loop... what gives?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:42:07.