我试图使用java在postgresql数据库中插入csv文件。
代码是
CopyManager copyManager = new CopyManager((BaseConnection) conn);
FileReader fileReader = new FileReader(filename);
copyManager.copyIn("COPY meta.fk_payment_temp(\n"+
"settlement_ref_no, order_type, fulfilment_type, seller_sku, wsn, \n" +
" order_id, order_item_id, order_date, dispatch_date, delivery_date, \n" +
" cancellation_date, settlement_date, order_status, quantity, order_item_value, \n" +
" refund, protection_fund, total_marketplace_fee, service_tax, \n" +
" settlement_value, commission_rate, commission, fee_discount, \n" +
" cancellation_fee, fixed_fee, emi_fee, total_weight, shipping_fee, \n" +
" reverse_shipping_fee, shipping_zone, token_of_apology, pick_and_pack_fee, \n" +
" storage_fee, removal_fee, invoice_id, invoice_date, invoice_amount, \n" +
" sub_category, total_offer_amount, my_offer_share, flipkart_offer_share)\n" +
" FROM STDIN with csv header delimiter ','", fileReader );csv文件和表中有41列。
错误的详细信息是:
其中:复制fk_payment_temp,第2行:"NFT-150331087GN00107XXXXXXX,预付,非FA,25 46-157,OD102411813209536003,166288248,“2015年3月25日,”.“
正如我们所看到的,错误出现在“2015年3月25日”中,但数据是
NFT-150331087GN00107XXXXXXX预付非FA 26 46-157 OD102411813209536003 166288248 25-3月15 26-3月15日27-3月15日31-3月15日交付1 339 3390 0 0 85.26 -10.54 243.2 15 -50.86 0 0 0 0.3 -29.4 0 0 0 IN27248 26-15 309婴儿娃娃0 0 0
我怎么能解决这个问题?
发布于 2015-10-26 16:11:59
我的经验是,这几乎总是由畸形的csv数据造成的。对格式的了解、如何正确转义等都是无可替代的,CSV也不简单。对于诸如嵌入行结束字符之类的事情,有很多规则。
一个很好的起点(如果你还没有找到答案的话)是通过一个电子表格运行数据,看看在错误的列上出现了什么。
https://stackoverflow.com/questions/30514192
复制相似问题