• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with executeQuery

 
Tokai Moshai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dileep Kamath
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tokai Moshai
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic