// ---------------------------------------------------------------------------------------------------------------- // Method: ReadRecords // Inputs: Result Set and Array List // Outputs: (by ref) Array List // Description: Read the Records, Fill Array List with JSON data // ---------------------------------------------------------------------------------------------------------------- public void ReadRecords(ResultSet rs, ArrayList records) { Gson gson = new GsonBuilder().create(); // Create Gson builder try // Try to get JSON, and save data to database { // while (rs.next()) // Loop through all the returned records, until EOF { // RFData RFMember = new RFData(); // Create new RF data // Capture the data from the record set RFMember.SampleNumber = rs.getInt("intSampleNum"); // Get sample # RFMember.XbeeID = rs.getInt("intXbeeID"); // Get Xbee ID RFMember.DeviceID = rs.getInt("intDeviceID"); // Get Device ID RFMember.RSSI = rs.getFloat("fltRSSI"); // Get RSSI RFMember.Latitude = rs.getFloat("fltLatitude"); // Get Latitude RFMember.Longitude = rs.getFloat("fltLongitude"); // Get Longitude RFMember.Yaw = rs.getFloat("fltYaw"); // Get Yaw RFMember.Pitch = rs.getFloat("fltPitch"); // Get Pitch RFMember.Roll = rs.getFloat("fltRoll"); // Get Roll RFMember.SampleDate = rs.getTimestamp("dtSampleDate"); // Get Sample Date // Print debug information to port SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println( "Got Record: # " + RFMember.SampleNumber + " - XbeeID: " + RFMember.XbeeID + ", RSSI: " + RFMember.RSSI + " Date/Time: " + ft.format(RFMember.SampleDate)); String json_record = gson.toJson(RFMember); // Get JSON data of this record records.add(json_record); // Add the JSON string to the record } } catch (Exception e) { System.err.println("ReadRecords: " + e.getMessage()); // Print the exception data and exit } }
// ---------------------------------------------------------------------------------------------------------------- // Method: ListDataByEntryID // Inputs: SampleNum // Outputs: RF Data Entry (JSON) // Description: Get RF Data Entry // ---------------------------------------------------------------------------------------------------------------- public String ListDataByEntryID(int SampleNum) { String json = ""; // Return JSON entry try // Try to get JSON, and save data to database { // // Print debug information to port System.out.println("Select RF Data from Table - Sample #: " + SampleNum); String sql_string; // Build up SQL string sql_string = "SELECT "; // Select SQL statement sql_string += "intSampleNum,"; // Field: intSampleNum sql_string += "intXbeeID,"; // Field: intXbeeID sql_string += "intDeviceID,"; // Field: intDeviceID sql_string += "fltRSSI,"; // Field: fltRSSI sql_string += "fltLatitude,"; // Field: fltLatitude sql_string += "fltLongitude,"; // Field: fltLongitude sql_string += "fltYaw,"; // Field: fltYaw sql_string += "fltPitch,"; // Field: fltPitch sql_string += "fltRoll,"; // Field: fltRoll sql_string += "dtSampleDate "; // Field: dtSampleDate sql_string += "FROM RF_Fields "; // Table: RF_Fields sql_string += "WHERE "; // Where statement sql_string += "intSampleNum = "; // Field on Where and condition sql_string += SampleNum; // Condition value System.out.println("SQL: " + sql_string); // Debug print the SQL statement Statement stmt = conn.createStatement(); // Build SQL statement ResultSet rs = stmt.executeQuery(sql_string); // Execute the SQL statement as a query while (rs.next()) // Loop through all the returned records, until EOF { // However, there should only be one return record Gson gson = new GsonBuilder().create(); // Create Gson builder RFData RFMember = new RFData(); // Create new RF data // Capture the data from the record set RFMember.SampleNumber = rs.getInt("intSampleNum"); // Get sample # RFMember.XbeeID = rs.getInt("intXbeeID"); // Get Xbee ID RFMember.DeviceID = rs.getInt("intDeviceID"); // Get Device ID RFMember.RSSI = rs.getFloat("fltRSSI"); // Get RSSI RFMember.Latitude = rs.getFloat("fltLatitude"); // Get Latitude RFMember.Longitude = rs.getFloat("fltLongitude"); // Get Longitude RFMember.Yaw = rs.getFloat("fltYaw"); // Get Yaw RFMember.Pitch = rs.getFloat("fltPitch"); // Get Pitch RFMember.Roll = rs.getFloat("fltRoll"); // Get Roll RFMember.SampleDate = rs.getTimestamp("dtSampleDate"); // Get Sample Date // Print debug information to port SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println( "Got Record: # " + RFMember.SampleNumber + " - XbeeID: " + RFMember.XbeeID + ", RSSI: " + RFMember.RSSI + " Date/Time: " + ft.format(RFMember.SampleDate)); json = gson.toJson(RFMember); // Get JSON data from this record } rs.close(); // Close the record set stmt.close(); // Close the statement if (json == "") // { // System.err.println("No Record Found!"); // Print the fact that no record was found } } // catch (Exception e) // Exception processing: { // System.err.println( "ListDataByEntryID: " + e.getMessage()); // Print the exception data and exit } // return json; // Return JSON string }