如何从JDBC截断Postgresql的表
发布时间:2020-12-15 05:02:52 所属栏目:Java 来源:网络整理
导读:我有一个 Postgresql数据库,我想使用JDBC截断一些表.我怎么做? 这是我尝试过的,但没有一个工作……甚至没有报告任何错误: 使用CallableStatement. try (Connection connection = getConnection(); CallableStatement statement = connection.prepareCall("
我有一个
Postgresql数据库,我想使用JDBC截断一些表.我怎么做?
这是我尝试过的,但没有一个工作……甚至没有报告任何错误: 使用CallableStatement. try (Connection connection = getConnection(); CallableStatement statement = connection.prepareCall("TRUNCATE " + tableName)) { return statement.execute(); } 使用Statement. try (Connection connection = getConnection(); Statement statement = connection.createStatement()) { return statement.execute("TRUNCATE " + tableName); } 使用PreparedStatement. try (Connection connection = getConnection(); PreparedStatement statement = connection.prepareStatement("TRUNCATE " + tableName)) { return statement.execute(); } 解决方法
截断后,我需要提交:
try (Connection connection = getConnection(); Statement statement = connection.createStatement()) { int result = statement.executeUpdate("TRUNCATE " + tableName); connection.commit(); return result; } 从the documentation开始:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – 使用web.xml和setMaxInactiveInterval设置会话超时
- java – 简单的protobuf编译与gradle
- java – 三星Galaxy 7“(GT-P6210)没有检测到USB调试?
- java – Hibernate:无法访问TransactionManager或UserTran
- rx-java – groupBy运算符,来自不同组的项交错
- 使用java获取文件所有者元数据信息
- java – 更改ExpandableListView中指示器的位置导致问题
- 使用iText在word文档中插入复杂的表格
- 【SpringBoot】14. SpringBoot多环境配置
- java – 我可以使用两个不同的线程在相同的套接字上读写吗?