使用JDBC批量新增資料和刪除資料

2021-10-05 08:07:15 字數 999 閱讀 1706

直接上碼:

1、批量新增資料

public

class

demo05

stmt.

executebatch()

;//執行批處理

conn.

commit()

;//提交事務

long end = system.

currenttimemillis()

; system.out.

println

("插入20000行資料,耗時:"

+(end - start)

+"ms");

}catch

(classnotfoundexception e)

catch

(sqlexception e)

finally

}catch

(sqlexception e)

try}

catch

(sqlexception e)}}

}

2、批量刪除資料

public

class

demo06

//執行批處理並返回批量執行的條數

int[

] result = stmt.

executebatch()

; conn.

commit()

;//提交事務

system.out.

println

(result.length);}

catch

(classnotfoundexception e)

catch

(sqlexception e)

finally

}catch

(sqlexception e)

try}

catch

(sqlexception e)}}

}

JDBC新增資料

使用drivergetconnect 取得的連線物件是connection型別,如果要對資料庫中的資料進行操作,我們還需要該物件取得另乙個物件來傳送sql語句,要取得這個傳送sql語句的物件我們需要用到connnetion中的這些方法 void close 關閉資料庫連線,使用完資料庫連線之後必須關...

Sqlite批量新增資料

今天遇到了往sqlite資料庫裡插入1400多條資料的情況,結果每次都需要一兩分鐘才能完成.搜尋了一下,在這裡找到了解決辦法,所需要的時間直接變成不到2秒 internal static void fastinsertmany dbconnection cnn dbtrans.commit catc...

PHP批量新增資料

連線資料庫 header content type text html charset utf 8 define db host 127.0.0.1 define db user root define db pass root define db name test define db port ...