mardi 24 février 2015

Using ORMLite to create table from Excel data

I have an Excel file with headers and rows. I've already got the Excel side "handled", thanks to Apache's excellent POI libraries. I can access the rows, headers, etc.


What I want to do now is create a database table based on the header information (column names) and using some parsing logic to establish the datatypes of the rows (already done).


I've used ORMLite very successfully in the past with known Java classes.


Is there a more elegant method than "hacking" a Java object together dynamically that matches the Excel data columns?


I'd like to get as close to this as possible:



Table t = conn.createTable("Table Name") ;
t.addColumn ("Column Name", String.class, 30) ; // Col name, data type, length
t.addColumn ("Another Column", Number.class, 5) ;


etc.


I know ORMLite can createTables based on an existing class (which is awesome), I'd like to have an API to create table data.


Looking at the ORMLite docs, TableUtils.createTable(...) still needs a Java class, as does DatabaseTableConfig.


If not ORMLite, any other suggestions? Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire