holding multiple values in an array

P

Praveen

Hi..,

While parsing a XML files I need to hold some of the values in an
array till the end of the iteration. After that I need to dump the
values in the DB table.

Here is an eg.
- These are the 4 values I want to hold from each file after I parse them.
Name, dept_no, employee_id, state

How do i create an array?
 
M

Matt Humphrey

Praveen said:
Hi..,

While parsing a XML files I need to hold some of the values in an array
till the end of the iteration. After that I need to dump the values in the
DB table.

Here is an eg.
- These are the 4 values I want to hold from each file after I parse them.
Name, dept_no, employee_id, state

How do i create an array?

What you're asking for is something like

String [] values = new String [4];
values[0] = name;
values[1] = dept_no;

but this is a poor way to go because it obscures the names of the fields.
It sounds more like you need a class, as is

class Employee {
String name;
String dept_no;
String employee_id;
String state;
}

create a new Employee each time you encounter the values. There are some
automated systems for doing this, but I havn't used them.

Alternatively, if you could put the fields into a map, as in
Map map = new HashMap ();
map.put ("name", name);
map.put("dept_no", dept_no);
etc.

I don't recommend this unless you are assured there is a an exact map
between your incoming data and your database schema.

Cheers,
Matt Humphrey (e-mail address removed) http://www.iviz.com/
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top