1

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.

1
  • ResultSet resultSet = query.executeQuery("Select COUNT(*) AS total FROM Questions"); and you are done.... Commented Sep 13, 2015 at 4:15

4 Answers 4

1

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)

Sign up to request clarification or add additional context in comments.

Comments

1

Change:

Select COUNT(*) FROM Questions AS total

to:

Select COUNT(*) AS total FROM Questions 

Comments

0

Your SQL query is a little bit wrong. Try:

ResultSet resultSet = query.executeQuery("Select COUNT(*) AS total FROM Questions");

Comments

0

Change your query like this,

The SQL syntax is

Select COUNT(*) AS total FROM Questions

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.