Reputation: 361
I was trying to import CSV into PostgreSQL using JDBC. I'm using this command:
sql ="\\copy data1_1 from 'C:\\Users\\legolas\\Desktop\\data1.csv' DELIMITERS ',' CSV";
But nothing gets written to the table. I'm not getting any errors.
When I use the same command in the psql
shell everything works perfectly.
I'm working on windows.
Upvotes: 2
Views: 271
Reputation: 66223
The command you are trying to send is start with \copy
. Every "command" starting with \
is NOT an SQL command but something the psql
shell handles by itself. Therefore you cannot \copy
in JDBC.
You can use the SQL variant copy
. But since copy
is a PostgreSQL special you have to fiddle with some driver internals. As this question states, the entry point for that is the class CopyManager
wich is "documented" here. In another question there is even a working example.
Upvotes: 1