java - Changing datatype definition for Jackcess -
i have program built takes access db , exports csv. works great program takes in exported csv has hardcoded regex , cannot handle different format of datatypes.
date
is: fri may 01 00:00:00 edt 2015
needs: 5/1/2015 00:00:00
boolean?
not sure if these field boolean but
is: true or false
needs: 0 or 1
currency
is: 0
needs: $0.00
strings
is: string
needs: "string"
after reading through docs line jumped out @ me "the row values typed java objects. in jackcess, column types represented java enum named datatype." appreciated.
use univocity-parsers that:
writer output = new stringwriter(); // use filewriter case csvwritersettings writersettings = new csvwritersettings(); //many options here, check tutorial objectrowwriterprocessor writerprocessor = new objectrowwriterprocessor(); // handles rows of objects , conversions string. writersettings.setrowwriterprocessor(writerprocessor); writersettings.setheaders("a", "b", "c", "d", "e", "f", "g", "h"); csvwriter writer = new csvwriter(output, writersettings); writerprocessor.convertfields(conversions.toboolean("0", "1")).add("c", "h"); // write "0" , "1" instead of "true" , "false" on column "c" , "h" writerprocessor.convertfields(conversions.todate("m/d/yyyy hh:mm:ss")).add("a", "e"); writerprocessor.convertfields(conversions.formattobigdecimal("$#0.00")).add("b", "d"); writer.writeheaders(); writer.processrecord(new date(), bigdecimal.ten, true, new bigdecimal("999.99"), new date(), "some text here", null, false); writer.processrecord(new date(), bigdecimal.zero, false, null, null, null, "more text here", null); writer.close(); system.out.println(output.tostring()); //and here result
the output be:
a,b,c,d,e,f,g,h 7/8/2015 07:09:58,$10.00,0,$999.99,7/8/2015 07:09:58,some text here,,1 7/8/2015 07:09:58,$0.00,1,,,,more text here,
disclosure: author of library. it's open-source , free (apache v2.0 license).
Comments
Post a Comment