我正在使用 Eclipse 的 Crystal Report 来生成动态报告(mysql 数据库)。
到目前为止,我可以将参数传递给报告,更改数据源连接:
String connectString = s.getDBpath();
String driverName = s.getClassforName();
String JNDIName = "";
String userName = s.getUserNameDB();
String password = s.getPasswordDB();
// Switch all tables on the main report and sub reports
CRJavaHelper.changeDataSource(clientDoc, userName, password, connectString, driverName, JNDIName);
问题是我想更改表名,但我不知道该怎么做。 我的意思是我有许多具有相同结构的表,每个用户都有自己的表,我想根据为登录用户指定的表生成报告。 那可能吗??
最佳答案
对于那些感兴趣的人,我找到了解决方案,并且我想分享它。 您所要做的就是根据查询生成报告。
将以下代码添加到您的报告查看器:
// ****** BEGIN POPULATE WITH RESULTSET SNIPPET ****************
{
// **** POPULATE MAIN REPORT ****
{
// Connection Info for fetching the resultSet
String connectStr = s.getDBpath();
String driverName = s.getClassforName();
String userName = s.getUserNameDB(); // TODO: Fill in database user
String password = s.getPasswordDB(); // TODO: Fill in valid password
String query = "select * from tbl2";//tbl2 is the table that you wanna make it as a report source
// As long the Resultset schema has the same field names and types,
// then the Resultset can be used as the datasource for the table
String tableAlias = "tbl1"; // TODO: Change to correct table alias
//tbl1 is the old report source,(data sr=ource for your report)
// Push the Java ResultSet into the report (this will then be the datasource of the report)
CRJavaHelper.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
tableAlias, "");
希望有帮助;)
关于mysql - Crystal 报告:change table name at runtime (jsp code),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26355028/