# Importing Okta System Log data into your database

**URL:** <https://devforum.okta.com/t/importing-okta-system-log-data-into-your-database/7477>\
**Category:** Questions\
**Tags:** java\
**Created:** [December 30, 2019, 9:29pm UTC](https://devforum.okta.com/t/importing-okta-system-log-data-into-your-database/7477 "2019-12-30T21:29:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![praxedis](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@praxedis](https://devforum.okta.com/u/praxedis)\
**Post date:** [December 30, 2019, 9:29pm UTC](https://devforum.okta.com/t/importing-okta-system-log-data-into-your-database/7477/1 "2019-12-30T21:29:19Z")

</div>

I’ve created my own polling/importer using the Spring @Scheduled annotation and comparing the latest database record timestamp with the latest Okta-side timestamp. My relevant snippet looks like this:

```
    // Convert to ISO Date. Okta is very specific about this. Format MUST be ISO
    		// 8601: 2019-11-13T15:38:49.230-06:00[America/Chicago]
    		sinceDate = ZonedDateTime.of(latestRecordDateTime, ZoneId.systemDefault()).toString();

    		String toDate = ZonedDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME);

    		// Now get the logs FROM OKTA between the latest record in the database until
    		// now and insert them into the database.
    		LogEventList logEvents = client.getLogs(toDate, sinceDate, null, null, "DESCENDING");

    		// Get the latest date that Okta has recorded of any activity.
    		LocalDateTime latestOktaDateTime = logEvents.stream().findFirst().get().getPublished().toInstant()
    				.atZone(ZoneId.systemDefault()).toLocalDateTime();

    		System.out.println("LATEST OKTA INSERT TIME: " + latestOktaDateTime.toLocalTime().toString());
    		System.out.println("LATEST DATABASE INSERT TIME: " + latestRecordDateTime.toLocalTime().toString());

    		// Compare the latest Okta DateTime value to the latest record in the database.
    		// Is it after?
    		boolean isAfter = latestOktaDateTime.isAfter(latestRecordDateTime);

    		if (isAfter) {

    			for (LogEvent item : logEvents) {

    // Import your Okta data into your local database
    }

    }

```

Anyone have an other implementations I can maybe get ideas from?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 18, 2024, 12:47am UTC](https://devforum.okta.com/t/importing-okta-system-log-data-into-your-database/7477/2 "2024-01-18T00:47:22Z")

</div>


