El escenario es el siguiente
-Reportes creados en crystal 9.0
-IDE JAVA Eclipse con integracion del plugin SAP
JSP + Reporte
El intento mas basico que quiero hacer es cambiar el origen de datos un pequeño fragmento de el codigo que estoy utilizando
Código:
<%@ page contentType="text/html;charset=UTF-8"
import="com.crystaldecisions.reports.reportengineinterface.*,
com.crystaldecisions.report.web.viewer.*" %>
<%@page import="java.util.Date"%>
<%@ page import="com.crystaldecisions.report.web.viewer.*" %>
<%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer" %>
<%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
<%@ page import="com.crystaldecisions.reports.sdk.ReportClientDocument" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.*" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ConnectionInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ConnectionInfos" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Fields" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.IConnectionInfo" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ParameterField" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.ParameterFieldDiscreteValue" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Values" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSource" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.application.*"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.*"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.document.*"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.definition.*"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.lib.*" %>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="javax.sql.DataSource"%>
<html>
<head>
<title>Change Database Connection - ODBC</title>
</head>
<body>
<%
String ipo=request.getParameter("fecha1");
String reportName = "CrystalReport1.rpt";
try {
IReportSourceFactory2 rptsrcFac=new JPEReportSourceFactory();
IReportSource reportSource=(IReportSource)rptsrcFac.createReportSource(reportName,request.getLocale());
ConnectionInfos connInfos = new ConnectionInfos();
IConnectionInfo connInfo1 = new ConnectionInfo();
String DBUSERNAME = "usuario";
String DBPASSWORD = "pass";
String SERVER = "192.168.1.12";
String CONNECTION_URL = "jdbc:postgresql://192.168.1.12:5432/dbname";
String DATABASE_CLASSNAME = "org.postgresql.Driver";
String DATABASE_DLL = "crdb_jdbc.dll";
String JDBC_CONNECTION_STRING = "Use JDBC=b(true);Connection URL=s(jdbc:postgresql://192.168.1.12:5432/dbname);" +
"Database Class Name=s(org.postgresql.Driver);Server=s(servername) ;" +
"Trusted_Connection=b(false) ;" +
"JDBC Connection String=s(!org.postgresql.Driver!jdbc:postgresql://192.168.1.12:5432/dbname;" +
"DatabaseName={database};user={userid};password={password}!)";
PropertyBag propertyBag = new PropertyBag();
propertyBag.put("Use JDBC", "true");
propertyBag.put("Connection URL", CONNECTION_URL);
propertyBag.put("Database Class Name", DATABASE_CLASSNAME);
propertyBag.put("Database DLL", DATABASE_DLL);
propertyBag.put("Server Type", "JDBC (JNDI)");
propertyBag.put("Server", SERVER);
propertyBag.put("Trusted_Connection", "False");
propertyBag.put("JDBC Connection String", JDBC_CONNECTION_STRING);
connInfo1.setUserName(DBUSERNAME);
connInfo1.setPassword(DBPASSWORD);
connInfo1.setAttributes(propertyBag);
connInfos.add(connInfo1);
String pop = "01/01/2014";
Fields fields=new Fields();
ParameterField paramfield=new ParameterField();
Values vals=new Values();
ParameterFieldDiscreteValue val=new ParameterFieldDiscreteValue();
paramfield.setName("fecha1");
val.setValue(pop);
vals.add(val);
paramfield.setCurrentValues(vals);
fields.add(paramfield);
CrystalReportViewer viewer=new CrystalReportViewer();
viewer.refresh();
viewer.setDatabaseLogonInfos(connInfos);
viewer.setReportSource(reportSource);
viewer.setParameterFields(fields);
viewer.setReuseParameterValuesOnRefresh(true);
viewer.setHasPageBottomToolbar(false);
viewer.setHasLogo(false);
viewer.setOwnPage(true);
viewer.setOwnForm(true);
viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);
viewer.dispose();
}
catch(ReportSDKException e) {
out.print("ERROR in the connection"+e);
}
catch(Exception ex) {
out.println(ex);
}
%>
</body>
</html>
He intentado configurar tomcat para que use JNDI y se configura exitosamente, el problema es que los reportes estan con conexion ODBC por que estan hechos en crystal report 9 y por problemas de licencia no se puede cambiar de opcion, este es un problema que tengo y no puedo resolverlo, alguien ha logrado cambiar la fuente de datos desde codigo para crystal report en JAVA muchas gracias ojala puedan ayudarme.