Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a program to read the content of an excel file to my-sql db. i have 40 columns in excel and i created a table of 40 fields. and i want to import the data from excel into corresponding table filed.

My doubt is, is there any better way to write preparedStatement than the following;

con.prepareStatement("insert into insurance.bank_stmnt_ds values(?,?,?,...,?(40 times))");

share|improve this question
Have you thought about using ODBC instead of Java? I haven't done this myself but here is one way – Jack Douglas Mar 7 '12 at 14:43

I am not sure whether you need compulsory callable statement or not.

If you are ready to use other ways, best way is convert your Excel sheet into CSV file and you can directly load data from CSV file into database by using following syntax:

"Load data infile "c:/filename.csv" into table tablename Fields terminated by ',' Lines terminated by '\r\n'"

This is sample syntax, and you can find the full syntax in net based on requirement.

share|improve this answer

If use the interface java.sql.PreparedStatement, the placeholder can not be simplified.

But If can use ORM tools, such as Hibernate. The code should be more clear like OOP.

Or, create a stored procedure. and use CallableStatement in order to avoid the ? placeholder.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.