We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge execute with IMailMergeDataSource

Hello,

I have got the problem with using IMailMergeDataSource. I wanted to
replace all merge fields with appropriate texts from database . My code look like:

class CustomerMailMergeDataSource implements IMailMergeDataSource {
Connection localConnection;

public CustomerMailMergeDataSource() throws ClassNotFoundException, SQLException {
Properties localProperties = new Properties();
localProperties.setProperty(“user”, “test”);
localProperties.setProperty(“password”, “test”);

Class.forName(“oracle.jdbc.driver.OracleDriver”);

localConnection = new OracleDriver().connect(“jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1523))(CONNECT_DATA=(SERVICE_NAME=DB)))”, localProperties);
}
@Override
public IMailMergeDataSource getChildDataSource(String arg0)
throws Exception {
return null;
}

@Override
public String getTableName() throws Exception {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean getValue(String arg0, Object[] arg1) throws Exception {
// TODO Auto-generated method stub
PreparedStatement pstmt = null;
ResultSet rs = null;
String queryGet = “SELECT value FROM data_values WHERE name = '” + arg0 + “’ AND id = 1311239 and rownum = 1”;
pstmt = localConnection.prepareStatement(queryGet);
rs = pstmt.executeQuery();
if ( !rs.next() )
return false;
arg1[0] = rs.getObject(1);
System.out.println( arg0 + " = " + rs.getObject(1) );
rs.close();
pstmt.close();
return true;
}

@Override
public boolean moveNext() throws Exception {
return true;
}
}

and in main:
doc.getMailMerge().execute( new CustomerMailMergeDataSource() );

and it never stops, i thought it would when there is no more mergefields in document.
How can i handle that?

Hi Pio,


Thanks for your inquiry.

Please create a simple application (for example a Java Console Application Project) that helps us reproduce the same problem on our end and attach it here for testing. Unfortunately, it is difficult to say what the problem is without the Document(s) and simplified application. We need your Document(s) and Simple Project to reproduce the problem. As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Best regards,