クリスタルレポートを使ってレポートを印刷する機能があります。問題は、このコードがデータベースからすべてのデータを出力することです。レポートに表示するレコードを選択できるように、プログラムでパラメーターまたはフィルターを設定するにはどうすればよいですか。Crystal Reports自体にパラメータの値を尋ねるプロンプトがあることは知っていますが、それは使いたくありません。
private void openReport() {
try {
ReportClientDocument rpt = new ReportClientDocument();
rpt.open(reportPath+fileName, 0);
rpt.getDatabaseController().logon(mdlLogin.dbUsername, mdlLogin.dbPassword);
Tables tables = rpt.getDatabaseController().getDatabase().getTables();
for(int i=0; i< tables.size(); i++){
ITable table = tables.getTable(i);
// dbane.owner.tablename
String original_qualifiedName = table.getQualifiedName();
String new_qualifierName = original_qualifiedName;
switch (database) {
case "ORACLE":
// SCHEMA.TABLENAME
String tableName = StringUtils.substringAfterLast(original_qualifiedName, ".").toUpperCase();
new_qualifierName = userOrSchemaName.toUpperCase()+"."+tableName;
break;
case "INFORMIX":
// DATABASE.OWNER.TABLENAME
new_qualifierName = dbname + ":" + userOrSchemaName + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
break;
case "MySQL":
// DATABASE.OWNER.TABLENAME
new_qualifierName = dbname + "." + userOrSchemaName + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
new_qualifierName = dbname + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
break;
default:
break;
}
String jdbcConnectionString = null;
String preQEServerName = null;
String driver = null;
switch (database) {
case "INFORMIX":
// !com.informix.jdbc.IfxDriver!jdbc:informix-sqli://localhost:40421/export:INFORMIXSERVER=cargool1!user={userid}!password={password}
jdbcConnectionString = "!com.informix.jdbc.IfxDriver!jdbc:informix-sqli://"+ip+":"+port+"/"+dbname+":INFORMIXSERVER="+dbservername+"!user={userid}!password={password}";
// jdbc:informix-sqli://localhost:40421/export:INFORMIXSERVER=cargool1
preQEServerName = "jdbc:informix-sqli://"+ip+":"+port+"/"+dbname+":INFORMIXSERVER="+dbservername;
// com.informix.jdbc.IfxDriver
driver = "com.informix.jdbc.IfxDriver";
break;
case "MySQL":
// !com.mysql.jdbc.Driver!jdbc:mysql://172.20.9.170:3306/hego
jdbcConnectionString = "!com.mysql.jdbc.Driver!jdbc:mysql://"+ip+":"+port+"/"+dbname;
// jdbc:mysql://172.20.9.170:3306/customer
preQEServerName = "jdbc:mysql://"+ip+":"+port+"/"+dbname;
// com.mysql.jdbc.Driver
driver = "com.mysql.jdbc.Driver";
break;
case "ORACLE":
// !oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:@//localhost:50000/tmsddb2
jdbcConnectionString = "!oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:@//"+ip+":"+port+"/"+dbname;
// jdbc:oracle:thin:@//localhost:50000/tmsddb2
preQEServerName = "jdbc:oracle:thin:@//"+ip+":"+port+"/"+dbname;
// "oracle.jdbc.driver.OracleDriver"
driver = "oracle.jdbc.driver.OracleDriver";
break;
default:
break;
}
table.setQualifiedName(new_qualifierName);
ConnectionInfo connInfo = new ConnectionInfo();
PropertyBag innerProp = new PropertyBag();
innerProp.put("JDBC Connection String", jdbcConnectionString);
innerProp.put("PreQEServerName", preQEServerName);
innerProp.put("Server Type", "JDBC (JNDI)");
innerProp.put("Database DLL", "crdb_jdbc.dll");
innerProp.put("Database", dbname);
innerProp.put("Database Class Name", driver);
innerProp.put("Use JDBC", "true");
innerProp.put("Database Name", dbname);
innerProp.put("Server Name", preQEServerName);
innerProp.put("Connection URL", preQEServerName);
connInfo.setAttributes(innerProp);
connInfo.setUserName(mdlLogin.dbUsername);
connInfo.setPassword(mdlLogin.dbPassword);
table.setConnectionInfo(connInfo);
rpt.getDatabaseController().setTableLocation(table, tables.getTable(i));
}
/*
* SubReport
*
*/
int numTables = rpt.getSubreportController().getSubreportNames().size();
for(int i=0; i<numTables; i++){////////////
String str = rpt.getSubreportController().getSubreportNames().getString(i);
Tables subTables = rpt.getSubreportController().getSubreport(str).getDatabaseController().getDatabase().getTables();
for(int j=0; j< subTables.size(); j++){
ITable table = subTables.getTable(j);
// dbane.owner.tablename
String original_qualifiedName = table.getQualifiedName();
String new_qualifierName = original_qualifiedName;
switch (database) {
case "ORACLE":
// SCHEMA.TABLENAME
String tableName = StringUtils.substringAfterLast(original_qualifiedName, ".").toUpperCase();
new_qualifierName = userOrSchemaName.toUpperCase()+"."+tableName;
break;
case "INFORMIX":
// DATABASE.OWNER.TABLENAME
new_qualifierName = dbname + ":" + userOrSchemaName + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
break;
case "MySQL":
// DATABASE.OWNER.TABLENAME
// new_qualifierName = dbname + "." + userOrSchemaName + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
new_qualifierName = dbname + "." + StringUtils.substringAfterLast(original_qualifiedName, ".");
break;
default:
break;
}
String jdbcConnectionString = null;
String preQEServerName = null;
String driver = null;
switch (database) {
case "INFORMIX":
// !com.informix.jdbc.IfxDriver!jdbc:informix-sqli://localhost:40421/export:INFORMIXSERVER=cargool1!user={userid}!password={password}
jdbcConnectionString = "!com.informix.jdbc.IfxDriver!jdbc:informix-sqli://"+ip+":"+port+"/"+dbname+":INFORMIXSERVER="+dbservername+"!user={userid}!password={password}";
// jdbc:informix-sqli://localhost:40421/export:INFORMIXSERVER=cargool1
preQEServerName = "jdbc:informix-sqli://"+ip+":"+port+"/"+dbname+":INFORMIXSERVER="+dbservername;
// com.informix.jdbc.IfxDriver
driver = "com.informix.jdbc.IfxDriver";
break;
case "MySQL":
// !com.mysql.jdbc.Driver!jdbc:mysql://172.20.9.170:3306/hego
jdbcConnectionString = "!com.mysql.jdbc.Driver!jdbc:mysql://"+ip+":"+port+"/"+dbname;
// jdbc:mysql://172.20.9.170:3306/customer
preQEServerName = "jdbc:mysql://"+ip+":"+port+"/"+dbname;
// com.mysql.jdbc.Driver
driver = "com.mysql.jdbc.Driver";
break;
case "ORACLE":
// !oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:@//localhost:50000/tmsddb2
jdbcConnectionString = "!oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:@//"+ip+":"+port+"/"+dbname;
// jdbc:oracle:thin:@//localhost:50000/tmsddb2
preQEServerName = "jdbc:oracle:thin:@//"+ip+":"+port+"/"+dbname;
// "oracle.jdbc.driver.OracleDriver"
driver = "oracle.jdbc.driver.OracleDriver";
break;
default:
break;
}
table.setQualifiedName(new_qualifierName);
ConnectionInfo connInfo = new ConnectionInfo();
PropertyBag innerProp = new PropertyBag();
innerProp.put("JDBC Connection String", jdbcConnectionString);
innerProp.put("PreQEServerName", preQEServerName);
innerProp.put("Server Type", "JDBC (JNDI)");
innerProp.put("Database DLL", "crdb_jdbc.dll");
innerProp.put("Database", dbname);
innerProp.put("Database Class Name", driver);
innerProp.put("Use JDBC", "true");
innerProp.put("Database Name", dbname);
innerProp.put("Server Name", preQEServerName);
innerProp.put("Connection URL", preQEServerName);
connInfo.setAttributes(innerProp);
connInfo.setUserName(mdlLogin.dbUsername);
connInfo.setPassword(mdlLogin.dbPassword);
table.setConnectionInfo(connInfo);
rpt.getSubreportController().getSubreport(str).getDatabaseController().setTableLocation(table, subTables.getTable(j));
}
}//////////////////////////
// rpt.getPrintOutputController().export(ReportExportFormat.RTF)
ReportViewerBean viewer = new ReportViewerBean();
viewer.init(new String[0], null, null, null);
viewer.setHasGroupTree(false);
viewer.setReportSource(rpt.getReportSource());
viewer.setHasExportButton(false);
viewer.setShowLogo(false);
viewer.start();
frmReportPanel panel = new frmReportPanel(rpt,fileName.replace(".rpt", ""));
Component[] components = viewer.getContentPane().getComponents();
panel.setLayout(new BorderLayout());
panel.add(components[0], BorderLayout.NORTH);
panel.add(components[1], BorderLayout.CENTER);
clsMain.openTab(fileName.replace(".rpt", ""), panel);
} catch (HeadlessException | ReportSDKExceptionBase | PropertyVetoException exception) {
Logger.getLogger(frmReportList.class.getName()).log(Level.SEVERE, null, exception);
utilErrorHandler.printError(exception.toString(), exception.getMessage(), M_STRPANELNAME, "PrintReport");
}
}