public TrafficCountRecord saveTrafficCountRecord(TrafficCountRecord trafficCountRecord)
      throws SQLException {

    try {
      Connection connection = getConnection();
      Statement s = connection.createStatement();
      String sql =
          "INSERT INTO trafficcount (pid, id, regionid, tagid, countdate, "
              + "daytype, starttime, endtime, w2, w3, pc, tx, ldv, ldc, hdc, "
              + "mdb, hdb) "
              + "VALUES ("
              + "(SELECT nextval('studyregion_pid_seq')),"
              + "'"
              + trafficCountRecord.getId()
              + "', '"
              + trafficCountRecord.getRegion()
              + "', "
              + "(SELECT id FROM tagdetails WHERE name='"
              + trafficCountRecord.getTag()
              + "' AND region = '"
              + trafficCountRecord.getRegion()
              + "')"
              + ", '"
              + trafficCountRecord.getDate()
              + "', '"
              + trafficCountRecord.getDayType()
              + "', '"
              + trafficCountRecord.getStartTime()
              + "', '"
              + trafficCountRecord.getEndTime()
              + "', '"
              + trafficCountRecord.getW2()
              + "', '"
              + trafficCountRecord.getW3()
              + "', '"
              + trafficCountRecord.getPC()
              + "', '"
              + trafficCountRecord.getTX()
              + "', '"
              + trafficCountRecord.getLDV()
              + "', '"
              + trafficCountRecord.getLDC()
              + "', '"
              + trafficCountRecord.getHDC()
              + "', '"
              + trafficCountRecord.getMDB()
              + "', '"
              + trafficCountRecord.getHDB()
              + "')";
      logger.debug("sql=" + sql);
      s.executeUpdate(sql);

      connection.close(); // returns connection to pool
    } catch (SQLException e) {
      logger.error(e.getMessage());
      throw e;
    }

    return trafficCountRecord;
  }
  public TrafficCountRecord updateTrafficCountRecord(TrafficCountRecord trafficCountRecord)
      throws SQLException {
    try {
      Connection connection = getConnection();
      Statement s = connection.createStatement();
      String sql =
          "UPDATE trafficcount SET "
              + " tagid = (SELECT id FROM tagdetails WHERE name='"
              + trafficCountRecord.getTag()
              + "'), "
              + " countdate = '"
              + trafficCountRecord.getDate()
              + "',"
              + " daytype = '"
              + trafficCountRecord.getDayType()
              + "',"
              + " starttime = '"
              + trafficCountRecord.getStartTime()
              + "',"
              + " endtime = '"
              + trafficCountRecord.getEndTime()
              + "',"
              + " w2 = '"
              + trafficCountRecord.getW2()
              + "',"
              + " w3 = '"
              + trafficCountRecord.getW3()
              + "',"
              + " pc = '"
              + trafficCountRecord.getPC()
              + "',"
              + " tx = '"
              + trafficCountRecord.getTX()
              + "',"
              + " ldv = '"
              + trafficCountRecord.getLDV()
              + "',"
              + " ldc = '"
              + trafficCountRecord.getLDC()
              + "',"
              + " hdc = '"
              + trafficCountRecord.getHDC()
              + "', "
              + " mdb = '"
              + trafficCountRecord.getMDB()
              + "', "
              + " hdb = '"
              + trafficCountRecord.getHDB()
              + "' "
              + "WHERE id = '"
              + trafficCountRecord.getId()
              + "'";
      logger.debug("UPDATE TrafficCountRecord SQL=" + sql);
      s.executeUpdate(sql);
      connection.close(); // returns connection to pool

    } catch (SQLException e) {
      logger.error(e.getMessage());
      throw e;
    }

    return trafficCountRecord;
  }