Reputation: 413
This question has been answered before here but the solutions that were posted are not working for me. Following is my code:
Statement query = this.conn.createStatement();
ResultSet resultSet = query.executeQuery("Select COUNT(*) FROM Questions AS total");
resultSet.next();
int totalQuestions = resultSet.getInt("total");
System.out.println(totalQuestions);
System.exit(1);
resultSet.close();
It just keeps on saying column total not found. I have tried it without "resultSet.next()" as well but same issue. I have also tried resultSet.getInt(1) but that doesn't work either.
Upvotes: 1
Views: 1809
Reputation: 1157
Change your query like this,
The SQL syntax is
Select COUNT(*) AS total FROM Questions
Upvotes: 0
Reputation:
Your SQL query is a little bit wrong. Try:
ResultSet resultSet = query.executeQuery("Select COUNT(*) AS total FROM Questions");
Upvotes: 0
Reputation: 53525
Change:
Select COUNT(*) FROM Questions AS total
to:
Select COUNT(*) AS total FROM Questions
Upvotes: 1
Reputation: 79838
The SQL syntax you want is
Select COUNT(*) AS total FROM Questions
or alternatively, you could just write Select COUNT(*) FROM Questions
and use resultSet.getInt(1)
Upvotes: 1