how to dynamically specify data type while creating the table in MS access using Java
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..
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.
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.
精彩评论