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

  • Home
  • SEARCH
  • 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 8332833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:50:03+00:00 2026-06-09T02:50:03+00:00

I have one database – pro . The table name is orders . The

  • 0

I have one database – pro. The table name is orders. The table have one field – total. The total have values – (100,200,300,400,500). Now I need to add all values from above database. How can I do this in Java? How can I write the query in Java? Please help me. This is my code part:

    public class GetCurrentDateTime {
     private Object sum;
    public int data(){  

try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");

    PreparedStatement statement =  con.prepareStatement("select sum(total) from orders where status='Q' AND WEEK(date) = WEEK(CURDATE()) AND YEAR(date) = YEAR(CURDATE())");
     ResultSet result = statement.executeQuery();
     println(result,getString(1));
    }

      catch(Exception exc){
      System.out.println(exc.getMessage());
      }
return 0;   
      }

    private void println(ResultSet result, Object string) {
// TODO Auto-generated method stub

     }
      private Object getString(int i) {
// TODO Auto-generated method stub
return sum;
    }
     }

This is my another class:

      public class Demo {
    public static void main(String[] args){
    GetCurrentDateTime obj = new GetCurrentDateTime();
    System.out.println(obj.data());

    }

   }

If I have to run my demo class means the sum of total number is displayed on tomcat console window. But is it displayed null 0 only. How to call sum(total) function in Java? Please help me.

  • 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-06-09T02:50:05+00:00Added an answer on June 9, 2026 at 2:50 am

    Try this instead your data method

    public double data(){
      double value=0.0;
      try{
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
    
         PreparedStatement statement =  con.prepareStatement("select sum(total) from orders where status='Q' AND WEEK(date) = WEEK(CURDATE()) AND YEAR(date) = YEAR(CURDATE())");
         ResultSet result = statement.executeQuery();
         result.next();
         String sum = result.getString(1);
         System.out.println(sum);
         value = Double.parseDouble(sum);
    
        } catch(Exception exc){
            System.out.println(exc.getMessage());
        }
        return value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one database table which contains 8 columns. One of the columns is
I have one database table TABLE_TIPS with two value 1. tips_id (auto increment) 2.
I have one large database table of request data, much like Apache request logs,
I have one field in Database ( Sql Server DB 2000) with varchar field
I have simple database - one table with 6 collumns. 3 of them i
I have one database that contains all of user information including name. Then there
I am using Rails 3. In one database table, I need to have one
I have one sqlite database which has one table in which I store the
I have one database table dealing with users login totals and another table dealing
I have created one database and one table user in that while running my

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.