Skip to Content
0
Former Member
Oct 19, 2011 at 04:02 AM

Assign Subreport parameters

50 Views

Hi all,

I have a java program which fill in the table and parameter fields in the crystal report :

private static void setDatabaseControllerResultSet(Database db, DatabaseController databaseController, String pdfid, ReportClientDocument reportDocument)

throws Exception {

int n = databaseController.getDatabase().getTables().size();

if (n>2)

{

mLogger.error("Crystal Report with " + n + " tables is not supported.");

throw new Exception("Not supported");

}

// Set main table

String query = "Select * from " + (pdfid);

PreparedStatement statement = db.getConnection().prepareStatement(query,

ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

String tableAlias = databaseController.getDatabase().getTables().getTable(0).getAlias();

ResultSet resultSet = statement .executeQuery();

databaseController.setDataSource(resultSet , tableAlias , "resultsetTable ");

}

private static void setParameterFields(Database db, ParameterFieldController ctrl, String pdfid)

throws Exception

{

String query = "SELECT * from " + (pdfid) + "_param";

PreparedStatement stmt = null;

try {

stmt = db.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

} catch (SQLException e) {

if (e.getErrorCode() == 2117)

{

mLogger.info("Table (" + pdfid + "_param) does not exist, no parameter field is set.");

return;

}

mLogger.error("SQL err: (" + e.getErrorCode() + ") " + e.toString());

throw e;

}

ResultSet rs = stmt.executeQuery();

for (boolean rv=rs.first(); rv; rv=rs.next())

{

String param = rs.getString(1);

String type = rs.getString(2);

/* Set parameter fields by type, default is String */

if (type.equalsIgnoreCase("Integer"))

ctrl.setCurrentValue("", param, rs.getInt(3));

else if (type.equalsIgnoreCase("Short"))

ctrl.setCurrentValue("", param, rs.getShort(3));

else if (type.equalsIgnoreCase("Float"))

ctrl.setCurrentValue("", param, rs.getDouble(3));

else if (type.equalsIgnoreCase("Date"))

ctrl.setCurrentValue("", param, rs.getDate(3));

else

ctrl.setCurrentValue("", param, rs.getString(3));

}

}

The program work fine but now i need to add the sub-report in my .rpt file, could anyone guide me hwo to modify the function so that it can assign the parameters into the sub-report? thx!