WordTemplate Class open setLocale setDataSource process save

WordTemplate.setDataSource Method


setDataSource(java.sql.ResultSet rs)
Sets a template's data source to a JDBC resultset.
setDataSource(java.lang.Object[] data, java.lang.String[] columnNames)
Sets a template's data source to a one-dimensional array of objects.

setDataSource(java.sql.ResultSet rs)

Syntax:
public int setDataSource(java.sql.ResultSet rs)
Description:

Sets a template's data source to a JDBC resultset. WordWriter will use the first row of the resultset as the data source.

Each merge field in a WordWriter template must bind to a data source field/value pair. The number of merge fields in the template may not exceed the number of values in the data source. However, the number of values in the data source may be greater than the number merge fields in the template.

In WordWriter 1.0, a template can have only one data source. Do not call setDataSource more than once for a single instance of WordTemplate.
Parameters:
Exceptions:
Example:
	...
	String sqlQuery = "SELECT TitleOfCourtesy, FirstName, LastName, Title FROM Employees";
	String templateFile = "/Basic/ResultSet/ResultSetTemplate.doc";
	InputStream iStream = null;
	Class.forName("com.softartisans.csvjdbc.CsvDriver").newInstance();
	conn = DriverManager.getConnection("jdbc:softartisans:csv:data");
	rs = stmt.executeQuery(sqlQuery);
	oWW = new WordTemplate();
	ServletContext ctx = this.getServletContext();
	iStream = new BufferedInputStream(ctx.getResourceAsStream(templateFile));
	oWW.open(iStream);
	//--- Pass the ResultSet object to setDataSource().
	oWW.setDataSource(rs);
	oWW.process();
	oWW.save(response, "ResultSetOutput.doc", false);
	...

Top


setDataSource(java.lang.Object[ ] data, java.lang.String[ ] columnNames)

Syntax:
public int setDataSource(java.lang.Object[] data, 
	java.lang.String[] columnNames)
Description:

Sets a template's data source to a one-dimensional object array. This method takes an object array of values and a string array of field names. The two arrays must contain the same number of elements. Each name in the array of field names must be the same as the corresponding merge field name in the template.

Each merge field in a WordWriter template must bind to a data source field/value pair. The number of merge fields in the template may not exceed the number of values in the data source. However, the number of values in the data source may be greater than the number merge fields in the template.

In WordWriter 1.0, a template can have only one data source. Do not call setDataSource more than once for a single instance of WordTemplate.
Parameters:
Exceptions:
Example:
	...
	//--- The array of values should be of type Object[].
	//--- These values are what will be populated into merge 
	//--- fields in the template document.
	Object[] arrValue = {"SoftArtisans", "WordWriter", "http://www.softartisans.com"};
	//--- The array of names should be of type string[].
	//--- The array indices of the name array should correspond
	//--- to the indices of the value array.
	String[] arrName = {"CompanyName", "ProductName", "URL"};
	WordTemplate oWW = null;
	String templateFile = "/Basic/ArrayVars/ArrayVarsTemplate.doc";
	InputStream iStream = null;
	...
	oWW = new WordTemplate();
	ServletContext ctx = this.getServletContext();
	iStream = new BufferedInputStream(ctx.getResourceAsStream(templateFile));
	oWW.open(iStream);
	//--- Set the data source of the document by passing
	//--- the value array and the name array initialized above.
	oWW.setDataSource(arrValue, arrName);
	oWW.process();
	oWW.save(response, "ArrayVarsOutput.doc", false);
	...

Top


WordTemplate Class open setLocale setDataSource process save

Copyright © 2003, SoftArtisans, Inc.