Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. public List<Wind2015> getResultsWind(String beginDate1, String endDate1, String[] connectingAreas1) throws Exception{
  2. int count = 0;
  3. List<Wind2015> myWind2015s = new ArrayList<>();
  4.  
  5. SimpleDateFormat readFormat = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy",
  6. Locale.ENGLISH);
  7. Date date2 = readFormat.parse(beginDate1);
  8. Date date3 = readFormat.parse(endDate1);
  9.  
  10.  
  11. String beginDate = new SimpleDateFormat("yyyy-MM-dd").format(date2);
  12. String endDate = new SimpleDateFormat("yyyy-MM-dd").format(date3);
  13.  
  14. ArrayList<String> connectingArea = new ArrayList<>(Arrays.asList(connectingAreas1));
  15.  
  16. StringBuilder inputs = new StringBuilder();
  17.  
  18. for (int i = 0; i < connectingArea.size(); i++) {
  19. if (i < connectingArea.size()-1) {
  20. inputs.append("?,");
  21. } else {
  22. inputs.append("?");
  23. }
  24. }
  25.  
  26.  
  27. String connectingAreaInputs = inputs.toString();
  28.  
  29. Connection connection = null;
  30. PreparedStatement prepareStatement = null;
  31. ResultSet myRs = null;
  32.  
  33. System.out.println(connectingAreaInputs);
  34.  
  35. try {
  36. connection = getConnection();
  37.  
  38. String sql = "SELECT * FROM `2015-wind` WHERE `TimeStamp` BETWEEN ? AND ? AND `ConnectingArea` IN ("+ connectingAreaInputs +")";
  39.  
  40. prepareStatement = connection.prepareStatement(sql);
  41.  
  42.  
  43. prepareStatement.setString(count+=1,beginDate);
  44. prepareStatement.setString(count+=1, endDate);
  45.  
  46. System.out.println(prepareStatement);
  47. for (String string : connectingArea) {
  48. System.out.println(string);
  49. count+=1;
  50. prepareStatement.setString(count, string);
  51. }
  52.  
  53.  
  54.  
  55. myRs = prepareStatement.executeQuery();
  56.  
  57. Wind2015 wind2015 = null;
  58.  
  59. while (myRs.next()) {
  60.  
  61. String timeStamp = myRs.getString("Timestamp");
  62. String connectingArea1 = myRs.getString("ConnectingArea");
  63. String value = myRs.getString("ActualWindEnergy");
  64.  
  65. wind2015 = new Wind2015(timeStamp, value, connectingArea1);
  66.  
  67. myWind2015s.add(wind2015);
  68. }
  69.  
  70. return myWind2015s;
  71.  
  72. } finally {
  73. close(connection, prepareStatement, myRs);
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement