1. 程式人生 > 其它 >jdbc 儲存大批量資料

jdbc 儲存大批量資料

技術標籤:jdbc資料庫

使用jdbc儲存12w行62列的資料用時86.5s

主要邏輯:controller層寫sql 每條sql後面帶1000條引數 ,
這樣的格式 insert into student (cno,name,score) values (1,張三,85),(2,李四,78)…
sql拼接完後 ,迴圈走下面這個方法

	 * 插入資料
	 * @param dataSource
	 * @param sql
	 * @param params
	 * @return
	 */
	public int buildInsert(String dataSource,String sql,
List<Object> params){ Connection conn = null; PreparedStatement ps = null; int rs = 0; try { // 獲取對不同資料庫的連線 conn = this.getConnection(dataSource); ps = conn.prepareStatement(sql); // PreparedStatement 設入 setPreparedStatementParams(ps,params); rs = ps.executeUpdate(); } catch
(SQLException e) { e.printStackTrace(); }finally{ close(conn,ps,null); } return rs; }