Dynamic Table population using Merge Fields - only data from one column is getting into table

I’m a novice in Java. I’m trying to populate a dynamic table (having two columns: EmpName and Location) in a Word document template using mail merge. The template i’m using has the fields like:

«TableStart:Employee»«EmpName» «Location»«TableEnd:Employee»

and the my code is:

ResultSet r = s.executeQuery("SELECT EmpName, Location FROM EmployeeDetails");
Document doc1 = new Document("C:\\EmpTemplate.doc");
String fields[] = doc1.getMailMerge().getFieldNames();
for (int i = 0; i < fields.length; i++)
doc1.getMailMerge().executeWithRegions("Employee", r);

Please provide some suggestions on the same.
Thanks in Advance.

Thanks for your inquiry. Your code looks good. Please make sure that data is not null or empty. Also attach your output document.
Best regards.

Hi there,
Thanks for the reply. The data is not null and I’m able to print the exact data from the result set generated. The output file generated is attached.
Thanks in Advance.

Thanks for additional information. I tried to use your template and all works fine on my side. See the attachment (input doc, output doc, code and data source). I think that your query return empty location.
Best regards.