parsing a fixed-width flat file to sql fields

C

clintsy

I need to parse a plain text file (1,000's of records) into an arraylist (or similar collection) that can be dumped into SQL fields. I know the field lengths but i don't know how to forward...
 
M

Marco Schmidt

clintsy:
I need to parse a plain text file (1,000's of records) into an arraylist (or similar collection) that can be dumped into SQL fields. I know the field lengths but i don't know how to forward...

Do you mean copying the data into a database?

Create a PreparedStatement stat with "insert into" in it. The exact
syntax depends on the table structure.

Then for each input line:
- Split the input string into several strings using String.substring.
- Call trim() on the strings to remove trailing whitespace.
- Copy fields into the PreparedStatement object with the correct index
and set method, e.g. stat.setString(index, value);
- Call the executeUpdate method of stat.

BTW: Please make your newsclient use no more than about 80 characters
per line!

Regards,
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top