• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Import Excel to Database and Export Database to Excel in Java

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Import data from Excel to database and export data from database to Excel are common tasks for developers. In this article, I will introduce how to import Excel to database and export database to excel in Java. To read and update database, I use JDBC (MySQL database is used in this article), to read and generate Excel file, I use Spire.XLS for Java API. This solution works for both the old 97-2003 and the new 2007 or above Excel formats.

Add Dependencies

First, you need to add needed dependencies for MySQL JDBC Driver and Spire.XLS for Java API in your maven project’s pom.xml file.

Export Database to Excel

Assume I have the following data table called “employees” in MYSQL database “pcb”.


In the following code example, you will see how to retrieve the data from the data table and insert into an Excel file using Spire.XLS for Java API:

Import Excel to Database

In the following code example, I will import data from the above generated Excel file back to the data table “employees” in MYSQL database.


I hope you learned how to import database to excel and export excel to database in Java from my article. Apart from interacting with database, the Spire.XLS for Java API also supports importing data from other data sources such as arrays and array lists to Excel, you can give it a try if you’re interested. Happy Coding!
    Bookmark Topic Watch Topic
  • New Topic