简体   繁体   中英

How to import CSV file data into a PostgreSQL table via java code?

I have a csv file which I want to import to table in postgres

The table contains 3 fields ( id text, name text, geo geometry ). The csv file is in the same format (3 values separate with comma).

I want to use java code in order to import the file ( input.csv ) into the table ( tbl )

How can I do it ? Is there a query which I pass the file path to the DB ?

您可以使用 OpenCSV 将 csv 文件读入 java 对象(这里是一个示例 - https://www.geeksforgeeks.org/mapping-csv-to-javabeans-using-opencsv/ ),然后使用 Java JPA Repository 插入数据进入数据库(这里是一个例子 - https://www.baeldung.com/spring-data-crud-repository-save

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM