• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Import Excel to Database and Export Database to Excel in Java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Introduction

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”.

IDEMP_NAMEAGEDEPTSALARY
001Sara22Sales3000
002Ben32Sales4300
003Jhon36Support5000
004Terry30Dev9000
005Chris27Test8000


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.


Conclusion

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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic