Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Wind2015> getResultsWind(String beginDate1, String endDate1, String[] connectingAreas1) throws Exception{
- int count = 0;
- List<Wind2015> myWind2015s = new ArrayList<>();
- SimpleDateFormat readFormat = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",
- Locale.ENGLISH);
- Date date2 = readFormat.parse(beginDate1);
- Date date3 = readFormat.parse(endDate1);
- String beginDate = new SimpleDateFormat("yyyy-MM-dd").format(date2);
- String endDate = new SimpleDateFormat("yyyy-MM-dd").format(date3);
- ArrayList<String> connectingArea = new ArrayList<>(Arrays.asList(connectingAreas1));
- StringBuilder inputs = new StringBuilder();
- for (int i = 0; i < connectingArea.size(); i++) {
- if (i < connectingArea.size()-1) {
- inputs.append("?,");
- } else {
- inputs.append("?");
- }
- }
- String connectingAreaInputs = inputs.toString();
- Connection connection = null;
- PreparedStatement prepareStatement = null;
- ResultSet myRs = null;
- System.out.println(connectingAreaInputs);
- try {
- connection = getConnection();
- String sql = "SELECT * FROM `2015-wind` WHERE `TimeStamp` BETWEEN ? AND ? AND `ConnectingArea` IN ("+ connectingAreaInputs +")";
- prepareStatement = connection.prepareStatement(sql);
- prepareStatement.setString(count+=1,beginDate);
- prepareStatement.setString(count+=1, endDate);
- System.out.println(prepareStatement);
- for (String string : connectingArea) {
- System.out.println(string);
- count+=1;
- prepareStatement.setString(count, string);
- }
- myRs = prepareStatement.executeQuery();
- Wind2015 wind2015 = null;
- while (myRs.next()) {
- String timeStamp = myRs.getString("Timestamp");
- String connectingArea1 = myRs.getString("ConnectingArea");
- String value = myRs.getString("ActualWindEnergy");
- wind2015 = new Wind2015(timeStamp, value, connectingArea1);
- myWind2015s.add(wind2015);
- }
- return myWind2015s;
- } finally {
- close(connection, prepareStatement, myRs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement