Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. public class RelexForecasting {
  2.  
  3.    //method for getting forecasts
  4.    public static double getForecast(Date day, String productCode, String outletCode, Double alpha) {
  5.  
  6.  
  7.       //get last weeks date
  8.       Date lastWeek = day.minusDays(7);
  9.  
  10.       //create database connection
  11.       Class.forName("com.mysql.jdbc.Driver").newInstance();
  12.       Connection con = DriverManager.getConnection("jdbc:mysql://localhost/database", "user", "pass");
  13.  
  14.       //SQL SELECT query
  15.       String query = ("SELECT * FROM customer_sales WHERE (date = lastWeek) AND (product_code = productCode) AND (outlet_code = outletCode);");
  16.  
  17.       //java statement
  18.       Statement st = conn.createStatement();
  19.  
  20.       //execute the query, and get a java resultset
  21.       ResultSet rs = st.executeQuery(query);
  22.  
  23.       //go through java resultset
  24.       while (rs.next()) {
  25.          double last_sales = rs.getDouble("sale");
  26.          double last_forecast = rs.getDouble("forecast");
  27.  
  28.          //exponential smoothing
  29.          double forecast = ((alpha * last_sales) + ((1 - alpha) * last_forecast))
  30.  
  31.          //return forecast
  32.          return forecast;
  33.       }
  34.  
  35.       //close connection
  36.       st.close();
  37.      
  38.    }
  39.  
  40.    public static void main(String []args) {
  41.  
  42.       getForecast(day, productCode, outletCode, alpha)
  43.  
  44.    }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement