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..
views:
70answers:
2
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
2009-11-18 06:54:01
That is ok, but i want to write a query to create a table with the dynamic data (Column name and type).
i2ijeya
2009-11-18 07:14:21
+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
2009-11-18 08:06:42