spark群集分区中的数据库连接对象

9gm1akwq  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(187)

我们试图在spark cluster中每个分区重用sql server数据库连接对象,但按照我们的实现方式,它试图为分区中的每个记录创建一个对象。
请让我们知道我们需要如何实现它,因为我们需要为每个分区而不是每个记录创建一个数据库对象。

InsurancePlan_DeleteRecord.foreachPartition(new ForeachPartitionFunction<Row>() {            
    @Override
    public void call(java.util.Iterator<Row> t) throws Exception {
        Connection InsuPlan = DriverManager.getConnection(dbProperties.getProperty("url"), dbProperties.getProperty("username"), dbProperties.getProperty("password"));
        System.out.println("Established Connection" + "" + InsuPlan);
        while (t.hasNext()) {
            Row row = t.next();
            Long RecordId = row.getLong(0);
            System.out.println("recordid" + "" + RecordId);
        }
    }
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题