I have to build a insert query string for creating a Prepared Statement. I have all the column name in Excel file.
There are more than 250 column in table, it takes much time and effort to create a simple insert query. I have to count the columns and put ? in values field in query.
Is there any other way to create these query.
Please Suggest.
Thanks In Advance
I can suggest a paradigm of doing this , implementing it would be a much larger issue though and from what I can make out , this is a pretty involved task !
You can use the JXL api to read these column names, you can also store their types in the same excel file (this will be useful when you are preparing the statement).
So your excel will be :
and so on
JXL will allow you to read all this into your java program, store this information in a Map (java.util.HashMap) , so at this point you have the names of columns in your program and their data types.
Now , about creating the prepared statement.
so at this point allColumnNames has all your column names
Make the prepared statement in segments :
There goes your prepared statement.
After this ,to insert stuff, you can iterate through the hashmap again and call setString or setInt or whatever depending on the “value” part of the hashmap.
As I said , its a long and involved process , but you can even modify this procedure to just set values in the excel file and then insert them directly from the excel into your table.