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?