• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 945
  • Last Modified:

empty ResultSet on executeQuery ("show tables")

I am getting a ResultSet with nothing in it on this:
preparedStatement = connection.prepareStatement("show tables");
ResultSet resultSet = preparedStatement.executeQuery();
(The resultSet is not null, but has 0 rows)

I have verified that the connection is to the correct db.
I also tried added this:
PreparedStatement preparedStatement = connection.prepareStatement("use mydb");
preparedStatement.execute();
but it has no effect.

In the MySQL terminal, show tables returns the table I know is in there.
What else can I look for?

0
allelopath
Asked:
allelopath
  • 5
  • 3
1 Solution
 
CEHJCommented:
Did you do

while  (resultSet.next())
    // DId it go in here?
}

?
0
 
CEHJCommented:
(Of course if it's an empty database, it won't have any tables)
0
 
allelopathAuthor Commented:
I did this:
int numberOfRows = resultSet.getRow();
in which numberOfRows is assigned 0

I tried your loop and it goes into it once (which surprises me)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
allelopathAuthor Commented:
So I guess 0 means 1 row returned.
0
 
CEHJCommented:
>>I tried your loop and it goes into it once (which surprises me)

In that case can you do

while  (resultSet.next())
    System.out.println(resultSet.getString(1));
}

?
0
 
CEHJCommented:
>>in which numberOfRows is assigned 0

It will be. You need to advance the cursor (by doing what i suggested e.g.) before it'll start counting rows
0
 
brunoguimaraesCommented:
I think the getRows() method doesn't return the actual number of rows the query returns, but the expected number of rows (or something like that).

I've seen someone complaining about it right here in EE.
0
 
allelopathAuthor Commented:
result.getString(1) returns the name of the table
thanks.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now