Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:06:26+00:00 2026-05-28T11:06:26+00:00

I created this code to allow me calculate the number of rows in my

  • 0

I created this code to allow me calculate the number of rows in my table. However, I’m not able to return the counted number with an error saying “cannot return a value from method whose result type is void.” Could someone show me where’ my error? Thanks alot!

public void num() throws Exception {
  try {
      // This will load the MySQL driver, each DB has its own driver
      Class.forName("com.mysql.jdbc.Driver");
      // Setup the connection with the DB
      connect = DriverManager.getConnection("jdbc:mysql://localhost/testdb?"
      + "user=root&password=");

      // Statements allow to issue SQL queries to the database
      statement = connect.createStatement();
      resultSet = statement.executeQuery("select * from testdb.emg");
      int count = 0;
      while (resultSet.next()) {
        count++;
      }  
      return count;
  } catch (Exception e) {
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:06:26+00:00Added an answer on May 28, 2026 at 11:06 am

    Try below code

     public int num() throws Exception {
     try {
     // This will load the MySQL driver, each DB has its own driver
     Class.forName("com.mysql.jdbc.Driver");
     // Setup the connection with the DB
     connect = DriverManager.getConnection("jdbc:mysql://localhost/testdb?"
     + "user=root&password=");
    
     // Statements allow to issue SQL queries to the database
     statement = connect.createStatement();
     resultSet = statement.executeQuery("select count(*) from testdb.emg");
    
     while (resultSet.next()) {
     return resultSet.getInt(1);
     }
    } catch (Exception e) {
    }
    

    Below were error

    1. public void num() throws Exception {

      should be

      public int num() throws Exception {

    2. For counting total rows you should use query select count(*) from testdb.emg

    Let me know incase of any problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created this code, it is supposed to use wordpress metabox functionality to save
I've created this code branch so that if the permalink settings do no match
I have created this Fiddle with this code: This is my problem I want
I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have made this code to open a database(created in SQLite browser) stored in
I created a class under 'src' dir. I'm using this code to access the
I'm using Drupal 7. And i created a block and embed this code: $contents
I created an image fading slideshow reading this article . The code looks like
Thanks to this site and a few others, I've created some simple code to
Hi guys i have this code to be created as a web service, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.