该驱动程序支持批处理语句以加快批量插入。
而且使用批处理的语句是很多比使用专有的INSERT语法更便携的(而据我所知,有一个多行插入和批量插入之间没有什么大的不同)
退房的PreparedStatement。 addBatch()
不支持UUID的原因可能是UUID不是Postgres核心的一部分,只是一个contrib模块。
编辑
关于执行异构语句
Postgres的驱动程序支持不同类型的批处理报表。
下正常工作:
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/postgres", "foo", "bar");
con.setAutoCommit(false);
Statement stmt = con.createStatement();
stmt.addBatch("create table foo (id integer, data varchar(100))");
stmt.addBatch("insert into foo values (1, 'one')");
stmt.addBatch("insert into foo values (2, 'two')");
stmt.addBatch("update foo set data = 'one_other' where id = 1");
stmt.executeBatch();
con.commit();
虽然你失去了自动转义是PreparedStatement的给你。
不应该将任何逸出你使用`PreparedStatement`,并在其中设置值处理的呢?批量更新不适用于插入多行? – ColinD 2011-02-04 16:18:30
你究竟是什么意思:*没有函数来逃避值消耗* – 2011-02-04 16:26:33
@ColinD对于同类语句来说没关系,但我也需要批量执行异类语句,并且Statement.addBatch只能接受SQL语句作为String,不是另一种说法。 – andreypopp 2011-02-04 17:06:12