Reading a CSV file into Java as a DB table

2019-07-14 05:54发布

问题:

I've found numerous posts about reading CSV with Java and the APIs they were pointing at all had a line-oriented approach when it came to reading a CSV file. Something like "while you get a line, get the values of every column".

I'd appreciate a higher-level API, like in Perl where DBI allows you to use SQL on CSV like if it where a DB table. Otherwise I'll have to implement lots of access logic by myself.

Is there such an API? Am I missing something? There are some references about JDBC drivers but most are projects that haven't been updated the last 5 years.

回答1:

You can use HSQL in order to do it, see the following links from the docs and a blog post describing exactly that.



回答2:

You could give H2Database a go - it is rather heavy weight, but at least it is maintained.



回答3:

This link might get you started in the right direction.

HTH



回答4:

Are you trying to avoid using a regular database for accessing CSV? MySQL supports CSV as one of it's table types if you are open to using a database system.



回答5:

yes, JDBC with a CSV driver. You can try implement yourself or just try something like HXTT



标签: java jdbc csv