views:

70

answers:

2

My application is extracting the data from excel sheet. I am storing the value and type of the data from the sheet into the ArrayList. ie., If my excel sheet consists of employee data, i will retrive [ Employee name, String] [ Employee id, number] and so on.. So i have to create a table with these names and with their respective data types. So how could i dynamically specify the data types for the attributes in the table. I am using JDBC,MS Access..

A: 

For each different data type, use a different class. You can either use the default java classes like String or Integer, or make your own depending on your further requirements. You can store all these classes in your ArrayList.

When retrieving your data, check which class is used and handle it appropriately.

Roalt
That is ok, but i want to write a query to create a table with the dynamic data (Column name and type).
i2ijeya
+1  A: 

Well, you read your data in a String, and for every value do String.matches(regex) to find out the datatype. For example do value.matches("\d"), if it mathces, then instantiate an Integer like, new Integer(value). Now, you should be able to add this new integer object into your List.

I hope you will be able to see how to go further. Check the instanceof or something while creating the table in the database.

Adeel Ansari