excel匯入資料庫,存在則更新不存在新增

2022-10-10 21:06:16 字數 1808 閱讀 5000

public

void

exceltodb() throws parseexception

catch

(exception e)

//匯入檔案

sheet rs = rwb.getsheet(0);//

表int rows = rs.getrows();//

得到所有的行

for(int i=1;i)

if(map == null

)

//沒查到就插入資料庫

所匯入實體類 entity = new

所匯入的實體類();

boolean flag = false

;

if(map.size() != 0

)

entity.setbname(rs.getcell(

1,i).getcontents());

entity.setbaddress(rs.getcell(

2,i).getcontents());

entity.setonesitekey(rs.getcell(

3,i).getcontents());

entity.settwositekey(rs.getcell(

5,i).getcontents());

//根據下標獲取excle表中經度緯度,取逗號前0後1

string s=rs.getcell(6

,i).getcontents();

string ss=s.split(","

);

if(!"".equals(s) && s!= null

)

if(!"".equals(rs.getcell(7,i).getcontents())&& rs.getcell(7,i).getcontents()!=null)

entity.setmanage(rs.getcell(

8,i).getcontents());

entity.setbtype(rs.getcell(

9,i).getcontents());

entity.setworkstation(rs.getcell(

10,i).getcontents());

entity.setbuiltuparea(rs.getcell(

12,i).getcontents());

entity.setupperarea(rs.getcell(

13,i).getcontents());

entity.setsparearea(rs.getcell(

14,i).getcontents());

entity.setpropertyunit(rs.getcell(

15,i).getcontents());

if(flag)

else

system.

out.println(i);

}}

2.固定路徑!(路徑寫死)

workbook rwb = null

; inputstream stream=null

;

try catch

(exception e)

//匯入檔案

sheet rs = rwb.getsheet(0);//

表int rows = rs.getrows();//

得到所有的行

Mysql插入資料,存在則更新,否則插入

mysql表中,有個聯合唯一索引 create table news visite id int 11 notnull auto increment comment 主鍵 news id bigint 11 default null comment 資訊id user id bigint 11 de...

excel匯入資料庫

在你的 中增加一列,利用excel的公式自動生成sql語句 concatenate 函式 具體方法如下 1 增加一列 假設是d列 2 在第一行的d列,就是d1中輸入公式 concatenate insert into table col1,col2,col3 values a1,b1,c1,3 此時...

Excel匯入資料庫

一 在excel中 新建一列,如把列名定為ab,下面放你的資料,比如1,2,3 二 開啟sql企業管理器,右擊你所需要匯入的資料庫,選擇匯入資料,下一步,資料來源選擇microsoft eccel 97 2000,選擇excel檔案繼續下一步,往下按,選擇sheet1 或者2,3 看你把資料放在那一...