Skip to Content
0
Former Member
Aug 21, 2013 at 05:32 PM

calling crystal report stored procedure from java

121 Views

Hi,

I am facing problem with calling crystal report from java.

I am passing params frommy java for calling report(it contains stored procedure and returns cursur)

could any one help me out ,how to call...

the following is the code which i used;;

Object reportSource = session.getAttribute("reportSource");

try {

//if the report source has not been opened

if (reportSource == null)

{

//you will need to modify report variable to point to your report

String report = "adjudicationprodreport.rpt";

IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();

reportSource = rptSrcFactory.createReportSource(report,request.getLocale());

session.setAttribute("reportSource", reportSource);

}

//create the viewer and render the report

CrystalReportViewer viewer = new CrystalReportViewer();

viewer.setReportSource(reportSource);

ConnectionInfos connInfos = new ConnectionInfos();

IConnectionInfo connInfo1 = new ConnectionInfo();

connInfo1.setUserName("tims32admin"); // We use the right user

connInfo1.setPassword("qazwsx123"); // And the right password

connInfos.add(connInfo1);

viewer.setOwnPage(true);

viewer.setOwnForm(true);

//set the viewer print mode

//viewer.setPrintMode(CrPrintMode.ACTIVEX);

viewer.setPrintMode(CrPrintMode.PDF);

//Create a Fields object collection to store the parameter fields in.

Fields parameterFields = new Fields();

//Create a ParameterField object for each field that you wish to set.

ParameterField pfield1 = new ParameterField();

ParameterField pfield2 = new ParameterField();

ParameterField pfield3 = new ParameterField();

ParameterField pfield4 = new ParameterField();

//You must set the report name. Set the report name to an empty string if your report does not contain a subreport; otherwise, the report name will be the name of the subreport

pfield1.setReportName("");

pfield2.setReportName("");

pfield3.setReportName("");

pfield4.setReportName("");

//Create a Values object and a ParameterFieldDiscreteValue object for each parameter field you wish to set.

//If a ranged value is being set, a ParameterFieldRangeValue object should be used instead of the discrete value object.

Values vals1 = new Values();

Values vals2 = new Values();

Values vals3 = new Values();

Values vals4 = new Values();

ParameterFieldDiscreteValue pfieldDV1 = new ParameterFieldDiscreteValue();

ParameterFieldDiscreteValue pfieldDV2 = new ParameterFieldDiscreteValue();

ParameterFieldDiscreteValue pfieldDV3 = new ParameterFieldDiscreteValue();

ParameterFieldDiscreteValue pfieldDV4 = new ParameterFieldDiscreteValue();

//----------- Initialize the parameter fields ----------

//Set the name and value for each parameter field that is added.

//Values for parameter fields are represented by a ParameterFieldDiscreteValue or ParameterFieldRangeValue object.

String user = new String("Dan Guo");

pfield1.setName("user");

pfieldDV1.setValue(user);

// Calendar calendar = Calendar.getInstance();

// calendar.set(2004, 1, 17);

String StartDate = "7/30/1999";

/* Calendar calendar2 = Calendar.getInstance();

calendar2.set(2004, 1, 30); */

String EndDate= "7/30/2013";

// Integer CustomerID = new Integer("5");

pfield2.setName("P_FROM_DATE");

pfieldDV2.setValue(StartDate);

pfield3.setName("P_TO_DATE");

pfieldDV3.setValue(EndDate);

Integer QueueID = new Integer("0");

pfield4.setName("P_QUEUEID");

pfieldDV4.setValue(QueueID);

//Add the parameter field values to the Values collection object.

vals1.add(pfieldDV1);

vals2.add(pfieldDV2);

vals3.add(pfieldDV3);

vals4.add(pfieldDV4);

//Set the current Values collection for each parameter field.

pfield1.setCurrentValues(vals1);

pfield2.setCurrentValues(vals2);

pfield3.setCurrentValues(vals3);

//pfield4.setCurrentValues(vals4);

//Add each parameter field to the Fields collection.

//The Fields object is now ready to be used with the viewer.

parameterFields.add(pfield1);

parameterFields.add(pfield2);

parameterFields.add(pfield3);

parameterFields.add(pfield4);

//set the parameters into the viewer

viewer.setParameterFields( parameterFields );

//refresh the viewer if necessary (only required once)

if (session.getAttribute("refreshed") == null)

{

viewer.refresh();

session.setAttribute("refreshed", "true");

}

viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

}

catch (Exception e){

}