Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. public ListOfCheckins readFromDB(double CoreMinY, double CoreMaxY) {
  2.         //checkins = new HashMap<String, Integer>();
  3.         ListOfCheckins checkins = new ListOfCheckins();
  4.  
  5.         Connection con = null;
  6.         java.sql.PreparedStatement pst = null;
  7.         ResultSet rs = null;
  8.  
  9.         String url = "jdbc:mysql://83.212.117.76:3306/ds_systems_2016?autoReconnect=true&useSSL=false";
  10.         String user = "omada8";
  11.         String password = "omada8db";
  12.  
  13.         try {
  14.             con = DriverManager.getConnection(url, user, password);
  15.             pst = con.prepareStatement("select POI, POI_name, POI_category, POI_category_id, latitude, longitude, time, photos"
  16.                     +" from checkins where (latitude between " + CoreMinY + " and " + CoreMaxY
  17.                     + ") " + "and (longitude between " + minX + " and " + maxX + ") " + "and time between \'" + minDatetime +"\' and \'"+ maxDatetime +"\';");
  18.             rs = pst.executeQuery();
  19.  
  20.             String POI, POI_name, POI_category, POI_category_id, time, photos;
  21.             double latitude, longitude;
  22.            
  23.             while (rs.next()) {
  24.                 POI = rs.getString(1);
  25.                 POI_name = rs.getString(2);
  26.                 POI_category = rs.getString(3);
  27.                 POI_category_id = rs.getString(4);
  28.                 latitude = rs.getDouble(5);
  29.                 longitude = rs.getDouble(6);
  30.                 time = rs.getString(7);
  31.                 photos = rs.getString(8);
  32.                 checkins.addCheckin(POI, POI_name, POI_category, POI_category_id, longitude, latitude, time, photos);
  33.             }
  34.         } catch (SQLException ex) {
  35.             Logger lgr = Logger.getLogger(Mapper.class.getName());
  36.             lgr.log(Level.SEVERE, ex.getMessage(), ex);
  37.  
  38.         } finally {
  39.             try {
  40.                 if (rs != null) {
  41.                     rs.close();
  42.                 }
  43.                 if (pst != null) {
  44.                     pst.close();
  45.                 }
  46.                 if (con != null) {
  47.                     con.close();
  48.                 }
  49.  
  50.             } catch (SQLException ex) {
  51.                 Logger lgr = Logger.getLogger(Mapper.class.getName());
  52.                 lgr.log(Level.WARNING, ex.getMessage(), ex);
  53.             }
  54.         }
  55.         return checkins;
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement