CSV Reader - Java for PostgreSQL -
i need load csv table in database.
below table structure.
column | type | --------------+------------------------+ ip_from | bigint ip_to | bigint country_code | character(2) country_name | character varying(64) region_name | character varying(128)
i'm using csv reader read , insert file.
csvreader products = new csvreader("e:\\test.csv"); products.readheaders(); while (products.readrecord()) { string ip_from = products.get("ip_from"); //int string ip_to = products.get("ip_to"); //int string country_code = products.get("country_code"); //char string country_name = products.get("country_name"); //char
however, code give me error since datatype ip_from , ip_to different.
it should bigint.
i try use parseint method, still not working.
the equivalent postgresql bigint java-type long
.
instead of using strings or integers 2 fields (that should strings anyways, alas) should use long:
long ipfrom = long.parselong(products.get("ip_from")); long ipto = long.parselong(products.get("ip_to"));
then again using java wrong approach if have once. if that's case, you're better off using copy command, illustrated in kayaman's answer
Comments
Post a Comment