DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Related

  • Instant Integrations With API and Logic Automation
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Getting Started With HarperDB and Java: Your First "Hello, World" Integration

Trending

  • How to Identify Bottlenecks and Increase Copy Activity Throughput in Azure Data Factory
  • Build a Multilingual Chatbot With FastAPI and Google Cloud Translation
  • Microservices Design Patterns for Highly Resilient Architecture
  • Unifying SecOps and Observability for Enhanced Cloud Security in Azure
  1. DZone
  2. Data Engineering
  3. Databases
  4. Scheduled Import of Excel Into Database

Scheduled Import of Excel Into Database

In this article, learn more about how to achieve a scheduled import and full automation from Microsoft Excel to a database.

By 
ryjfgjl xb user avatar
ryjfgjl xb
·
Apr. 22, 24 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
540 Views

Join the DZone community and get the full member experience.

Join For Free

Earlier, we introduced the method of importing Excel into the database with one click, which eliminates the cumbersome steps of importing Excel into the database and solves various problems that may be encountered in the process. We also introduced the method of bulk importing multiple Excel files into the database, which enables unattended bulk import. Now we will introduce how to achieve scheduled import and achieve full automation.

Example

As shown in the figure, we have a table called Product Information, which records all the product information of the company. When there are new products, data will be added to the table. When there are changes in product information, the table data may also be updated.

Now, we need to synchronize the data in this table with the database, and when the Excel data is updated, we can update the data in the database on a regular basis.

synchronize the data in this table with the database

Step 1: Create a Product Information Table in the Database

Use the ExcelToDatabase tool to import Excel to the database with one click.

ExcelToDatabase tool

product table

Step 2: Decide on the Update Method

There are generally two ways to update data: full update and incremental update

  1. Full update: This involves deleting all previously imported data from the database table and then importing all the data from the Excel table. This approach is simple and robust, ensuring consistency between the Excel and database data. However, it can consume more resources and time when the Excel data volume is large or updates are frequent. It is generally suitable for scenarios where the data volume is small or updates are infrequent or where historical data retention is not required.
  2. Incremental update: Based on the existing data in the database table, only the newly added or modified data in Excel is updated. This method requires a fixed unique identifier for each row of data to distinguish between data, such as the product ID here. Now we will introduce two update methods.

Full Update

We will first save the import configuration we just created and name it product information. The target table can be the table name we just imported and generated. The import mode can be selected as overwrite. Click save.

full update

In the software toolbar — scheduled tasks — add a new task, add a scheduled task called product information — full update (here we leave the default settings for the scheduled task and add them later).

scheduled tasks

Edit the Excel file by deleting, adding, and modifying a data record to test the effect. The image below shows the data in the database table before modification. We will delete Product 10, change the unit price of Product 1 to 99, and add a new record for Product 11.

change price

Check the database table data again, it has been updated

check the database table

Incremental Update

If a full update is in progress, stop it first.

Here, we choose the product id as the unique identifier for the data and set it as the primary key in the database table.

set it as the primary key

Select the update option for import mode and click Save.

Select the update option

Add a new scheduled task called Product Information — Incremental Update.

Add a new scheduled task called Product Information — Incremental Update.

Modify a data record to test the update. Here, we'll change the price for Product 105 to 85 and add a new record for Product 20. Before modification, the database table looks like this:

before modification

Modify and save the Excel as shown in the figure.

Modify and save the Excel as shown in the figure.

Check the database table again, it has been updated.

Check the database table again, it has been updated.

Scheduled Task Settings

Scheduled Task Settings

  • Sub-task type: Select the saved task or configuration.
  • Start/end time: Specify the effective period of the scheduled task.
  • Month: Can be filled from 1 to 12.
  • Week: Can be filled from 1 to 7, representing Monday to Sunday.
  • Day: Can be filled from 1 to 31.
  • Hour: Can be filled from 0 to 23.
  • Minute: Can be filled from 0 to 59.
  • Second: Can be filled from 0 to 59.

Using minutes as an example:

  • Every minute: The task runs every minute, i.e., it runs at every minute from 0 to 59.
  • Every n minutes: Enter 3 to run the task every 3 minutes, for example, it runs at the 2nd, 5th, 8th, 11th, etc., minutes.
  • At the nth minute: Specify which minute the task should run, such as running at the 0th minute.

For example, to run the task every day at 9:00 AM:

run the task every day at 9:00 AM

You can view the basic information of real-time scheduled tasks in the scheduled tasks interface:

view the basic information of real-time scheduled tasks

Note: The scheduled task requires the software to run all the time. When you click x to close the software interface, the software will default to immediately exit and stop the scheduled task. You can check Hide in the tray area instead of directly exiting the program in the software menu bar — Tools — Settings. After hiding, you can right-click the program icon in the tray area and choose Open main interface or Exit program.

How To Add ExcelToDatabase to Boot

Applications that require running scheduled tasks are usually placed on servers that run 24 hours a day without interruption, but if the scheduled tasks are run on your computer, you may need to restart the computer every day. In this case, we can add the program to the startup process, and the scheduled tasks will automatically run after the program is started.

Step 1: Create an Exe Shortcut

Create an Exe Shortcut

Step 2

Place the shortcut in the Windows startup folder, and the program under this file will start up with the computer.

My computer path is: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

shortcut

Other Timing Methods

Using the built-in scheduled tasks of ExcelToDatabase requires keeping the program open, and the scheduled tasks will automatically stop running after exiting the program. If you prefer to run scheduled tasks in the background without opening the program, you can use other dedicated task-scheduling programs to call the API provided by ExcelToDatabase.

For example, Windows’ built-in Task Scheduler provides a non-graphical interface for running tasks in the background and can automatically start with the computer.

task scheduler

You can refer to the following instructions for using the API.

Introduction and Download of ExcelToDatabase

  • ExcelToDatabase — Automation tool for batch importing Excel files into database
Database Integration

Published at DZone with permission of ryjfgjl xb. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Instant Integrations With API and Logic Automation
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Java and MongoDB Integration: A CRUD Tutorial [Video Tutorial]
  • Getting Started With HarperDB and Java: Your First "Hello, World" Integration

Partner Resources


Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: