Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.