【问题标题】:Spring JPA @Param of filename for postgres COPYSpring JPA @Param of filename for postgres COPY
【发布时间】:2018-12-09 03:42:13
【问题描述】:

我有以下连接到 PostgreSQL 数据库的接口:

public interface ExampleDAO extends JpaRepository<Example, Integer>
{
    @Modifying
    @Query(value="COPY my_table FROM :filename CSV HEADER", nativeQuery=true)
    public int copyMyTable(@Param("filename") String filename);
}

但是当我运行它时,我得到了

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement

我删除了@Param 并将文件名硬编码,它工作正常。传递的文件名是:

copyMyTable("C:\\path\\to\\my\\file.csv");

我对这个完全不知所措!

【问题讨论】:

    标签: postgresql file csv spring-data-jpa sqlbulkcopy


    【解决方案1】:

    判断from this threadPostgres 不支持这种语句中的绑定参数。

    【讨论】:

    • 感谢您对此的澄清!我最终在 Java 中逐行读取文件并通过 JPA 保存功能进行插入/更新,文件少于 100 行,因此性能没有问题。
    猜你喜欢
    • 2018-08-31
    • 1970-01-01
    • 2017-09-21
    • 2016-09-17
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多