Java在資料庫操作中批量插入資料

2021-05-05 21:29:53 字數 1132 閱讀 6756

class.forname(

"com.mysql.jdbc.driver

");  

connection con

=(connection) drivermanager.getconnection(

"jdbc:mysql://"+

"localhost:3306/excel2mysql",

"wanle",

"wanle

");  

//關閉事務自動提交  

con.setautocommit(

false

);  

******dateformat sdf

=new

******dateformat(

"hh:mm:ss:ss

");  

timezone t

=sdf.gettimezone();  

t.setrawoffset(

0);  

sdf.settimezone(t);  

long starttime

=system.currenttimemillis();  

preparedstatement pst

=(preparedstatement) con.preparestatement(

"insert into test04 values (?,'中國')

");  

for(

inti =0

; i

<

10000

; i++

)   

//執行批量更新  

pst.executebatch();  

//語句執行完畢,提交本事務  

con.commit();  

long endtime

=system.currenttimemillis();  

system.out.println(

"用時:"+

sdf.format(

newdate(endtime

-starttime)));  

pst.close();  

con.close(); 

如何快速在資料庫中插入資料

工作中很少用mysql插入資料,今天正好遇到,學習下 在toad mysql工具裡面,除了像execl 一樣手動插入資料之外,最好用insert語句插入資料,怎麼快速生成資料呢?1.右擊需要插入資料表,這裡是cd financing income,彈出generate sql 選擇to editor...

如何快速在資料庫中插入資料

工作中很少用mysql插入資料,今天正好遇到,學習下 在toad mysql工具裡面,除了像execl 一樣手動插入資料之外,最好用insert語句插入資料,怎麼快速生成資料呢?1.右擊需要插入資料表,這裡是cd financing income,彈出generate sql 選擇to editor...

MyBatis向資料庫中批量插入資料

foreach collection 指定要遍歷的集合 表示傳入過來的引數的資料型別。該引數為必選。要做 foreach 的物件,作為入參時,list 物件預設用 list 代替作為鍵,陣列物件有 array 代替作為鍵,map 物件沒有預設的鍵。當然在作為入參時可以使用 param keyname...