Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RelexForecasting {
- //method for getting forecasts
- public static double getForecast(Date day, String productCode, String outletCode, Double alpha) {
- //get last weeks date
- Date lastWeek = day.minusDays(7);
- //create database connection
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/database", "user", "pass");
- //SQL SELECT query
- String query = ("SELECT * FROM customer_sales WHERE (date = lastWeek) AND (product_code = productCode) AND (outlet_code = outletCode);");
- //java statement
- Statement st = conn.createStatement();
- //execute the query, and get a java resultset
- ResultSet rs = st.executeQuery(query);
- //go through java resultset
- while (rs.next()) {
- double last_sales = rs.getDouble("sale");
- double last_forecast = rs.getDouble("forecast");
- //exponential smoothing
- double forecast = ((alpha * last_sales) + ((1 - alpha) * last_forecast))
- //return forecast
- return forecast;
- }
- //close connection
- st.close();
- }
- public static void main(String []args) {
- getForecast(day, productCode, outletCode, alpha)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement