mysql - Crystal 报告:change table name at runtime (jsp code)

标签 mysql jsp crystal-reports

我正在使用 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/

相关文章:

mysql - MySQL 中计算字段的未知列

java - 使用用户输入通过 Web 应用程序安排作业

c# - XSD 到数据集(这也是一个 xsd?)

datetime - 在 Crystal Reports 中获取上一季度的开始和结束日期

crystal-reports - 打开报表时 Crystal Reports XI 挂起

PHP/MySQL 忽略小数点右边的数字

php - 当PHP android中的1个条件为真时,如何从服务器获取数据?

php - 上传文件重命名

javascript - 使用 JS 从文本区域获取值并将其传递给服务器(jsp),无需重新加载页面

jsp - 无法通过jsp :include添加包含在JSP中的cookie