Create a Java ResultSet using CSV file instead of a SQL statement

By | August 20, 2018
Questions:

I want to use a result set to hold my user data. Just one wrinkle – the data is in a CSV (comma delimited) format, not in a database.

The CSV file contains a header row at the top, then data rows. I would like to dynamically create a result set but not using an SQL query. The input would be the CSV file.

I am expecting (from my Java experience) that there would be methods like rs.newRow, rs.newColumn, rs.updateRow and so on, so I could use the structure of a result set without having any database query first.

Are there such methods on result sets? I read the docs and did not find any way. It would be highly useful to just build a result set from the CSV and then use it like I had done an SQL query. I find it difficult to use a java bean, array list of beans, and such – because I want to read in CSV files with different structures, the equivalent of SELECT * FROM in SQL.

I don’t know what the names or numbers of columns will be in advance. So other SO questions like “Manually add data to a Java ResultSet” do not answer my needs. In that case, he already has an SQL created result set, and wants to add rows.

In my case, I want to create a result set from scratch, and add columns as the first row is read in. Now that I am thinking about it, I could create a query from the first row, using a statement like SELECT COL1, COL2, COL3 ... FROM DUMMY. Then use the INSERT ROW statement to read and insert the rest. (Later:) But on trying that, it fails because there is no real table associated.

Answers:

Leave a Reply

Your email address will not be published. Required fields are marked *