SQL語句插入資料庫2種方式

2021-07-10 03:48:08 字數 871 閱讀 5826

資料庫批量插入2種方法:

1.直接插入

sql = 「insert into rpt_count_log values(『pow_power=」+i+」』,』」+starttimes+」』,』」+endtimes+」』,』1』,』9』,』0x053502』,』1』)」;

sta.executeupdate(sql);

一條一條的執行,這種方法效率非常低,不適合大資料量的插入。

2.批量插入

首先,最重要的一點:將資料庫自動提交關閉con.setautocommit(false);

public class dbconn 

catch(exception e)

return sta;

}// 獲得連線

public connection getconnection()

//關閉資料庫

public void closemsg()

catch(exception e)

}

其次,設定批量插入的規模。例如此處是1620=810*2條記錄再一次性提交。

ps:由於之前將自動提交關閉,在批量執行之後要提交commit;新增一條要addbatch()。

public void insert(int nesum, int sn, string start, string end) throws sqlexception

}

sta.executebatch();

con.commit();

dbcon.connmsg();

}

學習資料庫SQL語句2

2018年11月15日 下午 1.where 子句用於規定選擇的標準。語法 select 列名稱 from 表名稱 where 列 運算子 值 例子 select from persons where city beijing 注意 引號的使用 文字值使用單引號,數值直接書寫 請注意,我們在例子中的...

把excel資料生成sql插入資料庫語句

excel 有a b c三列資料,希望匯入到資料庫users表中,對應的字段分別是name,age 在你的excel 中增加一列,利用excel的公式自動生成sql語句,方法如下 1 增加一列 d列 2 在第一行的d列,就是d1中輸入公式 concatenate insert into users ...

把excel資料生成sql插入資料庫語句

excel 有a b c三列資料,希望匯入到資料庫users表中,對應的字段分別是name,age 在你的excel 中增加一列,利用excel的公式自動生成sql語句,方法如下 1 增加一列 d列 2 在第一行的d列,就是d1中輸入公式 concatenate insert intousers n...