title: What is the alternative in JPA for a preparedStatement inside of the other in JDBC?
body: <pre><code> PreparedStatement pstmt1=conn.prepareStatement("select * from vehicles");
           ResultSet rs1=pstmt1.executeQuery();
           while(rs1.next()){
           int id=rs1.getInt("id");
  
           PreparedStatement pstmt2=conn.prepareStatement("select lat,lng from        vehicles where vehicle_id=123 and id=?");
  
           pstmt2.setInt(1,(id+1));
           //out.println("here i am");
           ResultSet rs2=pstmt2.executeQuery();
          double lat1=Math.toRadians(rs1.getDouble("lat"));
          double lng1=Math.toRadians(rs1.getDouble("lng"));
  
          while (rs2.next()){
  
           lat2=Math.toRadians(rs2.getDouble("lat"));
           lng2=Math.toRadians(rs2.getDouble("lng"));
  
          }
  </code></pre>
  
  <p>Actually, i am trying to calculate the total distance covered in km by a vehicle throughout the day. For this, i am using each latitude and longitude point as the source and destination for each small distances and at last adding them, i get the total sum. I am using JPA and could not figure out how to use this concept in the above code in JPA. Can anybody help me out? It would be a great pleasure. :) </p>