Java 如何通过jdbc将数据从数据流加载到postgresql中

Java 如何通过jdbc将数据从数据流加载到postgresql中,java,postgresql,Java,Postgresql,如何通过jdbc将数据从数据流加载到postgresql中 我们将在内存中获取数据流或数组, 是否有任何方法将流数据加载到postgresql中? 使用insert效率太低。您需要将准备好的语句与批插入一起使用。请查看页面:,该页面描述了此方法的性能和安全优势。下面的代码来自该页面 String sql = "insert into employee (name, city, phone) values (?, ?, ?)"; Connection connection = new getCon

如何通过jdbc将数据从数据流加载到postgresql中 我们将在内存中获取数据流或数组, 是否有任何方法将流数据加载到postgresql中?
使用insert效率太低。

您需要将准备好的语句与批插入一起使用。请查看页面:,该页面描述了此方法的性能和安全优势。下面的代码来自该页面

String sql = "insert into employee (name, city, phone) values (?, ?, ?)";
Connection connection = new getConnection();
PreparedStatement ps = connection.prepareStatement(sql);

final int batchSize = 1000;
int count = 0;

for (Employee employee: employees) {

    ps.setString(1, employee.getName());
    ps.setString(2, employee.getCity());
    ps.setString(3, employee.getPhone());
    ps.addBatch();

    if(++count % batchSize == 0) {
        ps.executeBatch();
    }
}
ps.executeBatch(); // insert remaining records
ps.close();
connection.close();

感谢您的回复,但我想知道是否有某种方法可以在Mysql jdbc
Statement stmt=conn.createStatement()stmt.setLocalInfileInputStream(InputStream输入)中使用语句stmt=conn.createStatement()stmt.setLocalInfileInputStream(InputStream输入流)之类的方法