简体   繁体   English

如何将Excel工作表列映射到数据库中的列?

[英]How to map excel sheet columns to columns in database?

I need to read an excel file and upload the data from the excel sheet to the database. 我需要读取一个Excel文件,并将数据从Excel工作表上传到数据库。

The excel sheet will have information of users like firstname, lastname, email, age, joining date, country, etc. Excel工作表将包含用户的信息,例如名字,姓氏,电子邮件,年龄,加入日期,国家/地区等。

I will also have similar User table in the database. 我在数据库中还将有类似的User表。

I just need to read each row from excel sheet and insert into table. 我只需要从Excel工作表中读取每一行并插入到表格中即可。

But for this I need to know which column in excel will go into which column in db tables. 但是为此,我需要知道excel中的哪一列将进入db表中的哪一列。

I plan to do this with the static mapping of column names in table( ie property names of user java bean) to the corresponding indexes in the excel sheet. 我计划使用表中列名(即用户Java bean的属性名)到excel工作表中相应索引的静态映射来做到这一点。

eg lastName maps to index 2 in the excel sheet. 例如lastName映射到Excel工作表中的索引2。

Please help me if this is the right approach? 如果这是正确的方法,请帮助我?

What is the best possible way of doing this? 最好的方法是什么?

THis is alright. 没关系。 You can also have the top row as heading, (if creating the Excel sheet is in your control) to verify the fields. 您也可以将第一行作为标题(如果在控件中创建Excel工作表)以验证字段。 It's pretty straight forward to do this: 这样做很简单:

  1. Use Apache POI to read Excel sheet. 使用Apache POI读取Excel工作表。
  2. Add using JDBC batch insert . 使用JDBC批处理插入添加。

Please follow the below steps for the reading from excel and inserting in to the database. 请按照以下步骤从excel中读取并插入数据库。

http://poi.apache.org/spreadsheet/index.html http://poi.apache.org/spreadsheet/index.html

1.its simple API provided by the Apache. 1.其简单的API由Apache提供。 pointo tbe noted .Please make sure the file name and tab name is unique. 注意事项。请确保文件名和标签名是唯一的。 2. Also it will be easier to read from the csv file so that it can be inserted in the database normal control files and you will get the enough support from the oracle. 2.同样,从csv文件中读取内容也将更加容易,以便可以将其插入数据库常规控制文件中,并且您将从oracle中获得足够的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM