MailMerge with regular arrays (Java.word)

Hi Friend,
can you please let me know if i can do mailmerge using regular arrays?
my code below does not work or does not do anyhing to my document.
i populate the arrays fieldArray and valueArrays with data from database.
on my template word document i made merge-fields with the fields name which i have in the array fieldArrys… Please Help

try {
doc.getMailMerge().execute(fieldArray,
valueArray);
} catch (Exception e2) {
e2.printStackTrace();
}

@marcsr,

You can build logic on the following code to get the desired output:

Document doc = new Document("E:\\temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToDocumentEnd();
builder.writeln();
builder.insertField(" MERGEFIELD FullName", null);
builder.writeln();
builder.insertField(" MERGEFIELD Company",null);
builder.writeln();
builder.insertField(" MERGEFIELD Address",null);
builder.writeln();
builder.insertField(" MERGEFIELD Address2",null);
builder.writeln();
builder.insertField(" MERGEFIELD City",null);

String[] fieldArray = new String[]{"FullName", "Company", "Address", "Address2", "City"};
Object[] valueArray = new Object[]{"James Bond", "MI5 Headquarters", "Milbank", "", "London"};

doc.getMailMerge().execute(fieldArray, valueArray);

doc.save("E:\\Temp\\awjava-19.8.docx");

Hi Awais.
Thank you very much for responding back to me.
however this code does not work, because i already have values in two arrays
my arrays are already pre-populated with data

fieldArray contains data like this:
FullName
Company
Address
Address2

valueArray contains data like this:
John Jackson
Bank of America
123 Main Street
PO Box 123

when i execute this code does not work or does not do any mailmerge
doc.getMailMerge().execute(fieldArray, valueArray);

remember then second parameter is an array not an object, i don’t know if this may be the problem.

please help.

thanks

@marcsr,

Please see these sample input/output Word documents (Docs.zip (19.7 KB)) and try running the exact code from my post. Hope, this helps.