spark 批量插入数据到数据库中

使用批量处理的方式提高效率
connection.setAutoCommit(false) //设置手动提交

val sql = "xxxx"
pstmt = connection.prepareStatement(sql)

for (ele <- list){
    ······

    pstmt.addBatch()
}

pstmt.executeBatch()  //执行批处理
connection.commit()   //手动提交

猜你喜欢

转载自blog.csdn.net/chengliangyao/article/details/80620679