title: Get Sum(total) in Java from MySQL database
body: <p>I have one database - <strong><em>pro</em></strong>. The table name is <strong><em>orders</em></strong>. The table have one field - <strong><em>total</em></strong>. The total have values - <strong><em>(100,200,300,400,500)</em></strong>. 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:</p>
  
  <pre><code>    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;
      }
       }
  </code></pre>
  
  <p>This is my another class:</p>
  
  <pre><code>      public class Demo {
      public static void main(String[] args){
      GetCurrentDateTime obj = new GetCurrentDateTime();
      System.out.println(obj.data());
  
      }
  
     }
  </code></pre>
  
  <p>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 <code>sum(total)</code> function in Java? Please help me.</p>