コード例 #1
0
 public void processVmCpuData() {
   try {
     PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertVmCpuInfo());
     AggregationOutput aggregationOutput =
         mongoTask.getAggregatedOutput("cpuinfo", Queries.getCpuInfoQuery());
     for (DBObject obj : aggregationOutput.results()) {
       String hostname = (String) obj.get("_id");
       double usage = Double.parseDouble(obj.get("usage").toString());
       pstmt.setTimestamp(1, new java.sql.Timestamp(timeStamp.getTime()));
       pstmt.setString(2, hostname);
       pstmt.setDouble(3, usage);
       pstmt.setInt(4, 1);
       pstmt.addBatch();
     }
     pstmt.executeBatch();
   } catch (SQLException s) {
     s.printStackTrace();
   }
 }