admin管理员组文章数量:1399119
Since am not allowed to comment on the original discussion (Inserting data with UCanAccess from big text files is very slow) because I don't have enough points, am having to start a new one.
I have implemented the code discussed above (thank you Gord Thompson), but it is not handing nulls. When I either use the word 'null' (without quotes) or simply leave no value in my CSV field, it will not import into a predefined table (in this case a nullable double field). This even includes when I implement my own com.healthmarketscience.jackcess.util.ImportFilter.
Looking at the Jackcess code, I see the problem in com.healthmarketscience.jackcess.impl.ColumnImpl (in Jackcess 4.0.0 JAR). The relevant method is the ColumnImpl::toNumber method, where, in the event of encountering a null, returns a BigDecimal.ZERO, which is obviously not null
Having said all that, my code is failing in ColumnImpl::toNumber on the return statement at the end...
return Double.valueOf(value.toString());
...meaning I have not successfully passed in a null at this point, just an empty string. I can override this within the ImportFilter implementation, but as indicated above, it would still return the non-null BigDecimal.ZERO value.
Not sure how to get around this other than return special values that I can convert to null with successive update queries. Also, predefined table / field level macros in MS Access do not seem to get triggered when importing data (at least not that I've seen so far). Either solution is not ideal though, it would be nice if nulls were handled properly.
Any ideas?
Thanks,
Matthew
P. S. trying to do a call out to Gord Thompson, but the '@' thing is not working for me (not enough points, perhaps?).
Since am not allowed to comment on the original discussion (Inserting data with UCanAccess from big text files is very slow) because I don't have enough points, am having to start a new one.
I have implemented the code discussed above (thank you Gord Thompson), but it is not handing nulls. When I either use the word 'null' (without quotes) or simply leave no value in my CSV field, it will not import into a predefined table (in this case a nullable double field). This even includes when I implement my own com.healthmarketscience.jackcess.util.ImportFilter.
Looking at the Jackcess code, I see the problem in com.healthmarketscience.jackcess.impl.ColumnImpl (in Jackcess 4.0.0 JAR). The relevant method is the ColumnImpl::toNumber method, where, in the event of encountering a null, returns a BigDecimal.ZERO, which is obviously not null
Having said all that, my code is failing in ColumnImpl::toNumber on the return statement at the end...
return Double.valueOf(value.toString());
...meaning I have not successfully passed in a null at this point, just an empty string. I can override this within the ImportFilter implementation, but as indicated above, it would still return the non-null BigDecimal.ZERO value.
Not sure how to get around this other than return special values that I can convert to null with successive update queries. Also, predefined table / field level macros in MS Access do not seem to get triggered when importing data (at least not that I've seen so far). Either solution is not ideal though, it would be nice if nulls were handled properly.
Any ideas?
Thanks,
Matthew
P. S. trying to do a call out to Gord Thompson, but the '@' thing is not working for me (not enough points, perhaps?).
Share Improve this question asked Mar 26 at 19:20 lastfreedomlastfreedom 416 bronze badges 2 |1 Answer
Reset to default 1The following logic for ImportFilter::filterRow works (at least for my scenario in which I don't use empty strings)...
public Object[] filterRow(Object[] row) throws SQLException, IOException {
Object[] lclReturn = new Object[row.length];
for (int i = 0; i < row.length; i++) {
Object lclObject = row[i];
if (lclObject != null) {
if (!"".equals(lclObject.toString().trim())) {
lclReturn[i] = lclObject;
} else {
lclReturn[i] = null;
}
} else {
lclReturn[i] = null;
}
}
return lclReturn;
}
本文标签: javaInserting data with UCanAccess from big text files is very slowProcessing NullsStack Overflow
版权声明:本文标题:java - Inserting data with UCanAccess from big text files is very slow - Processing Nulls - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744130128a2592140.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
toNumber()
logic. if you implemented your filter to pass in a propernull
value for blank values, then that should work. – jtahlborn Commented Mar 26 at 19:59