Java server-side build Report document: Using SQL Server Reporting Service (SSRS)

Source: Internet
Author: User

SQL Server report Service (SSRS) provides both ASP. NET and WinForm client component encapsulation, so using C # to implement the export functionality of SSRS reports requires only the appropriate components.

Java Operations SSRS, you need to use the SSRS Report Server app site, which is the SSRS Reports Web view page that gets the report to access by sending a GET request and passes the report parameters, and also indicates the output report file format.

SSRS Key Parameters:

    • Rs:format, indicating the output file format, PDF, EXCEL, word, etc.;

Note: The Chinese report path and Chinese parameters need to be URL encoded.

The sample code looks like this:

 PackageLims.ssrs;ImportJava.io.BufferedInputStream;ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileOutputStream;Importjava.io.IOException;ImportJava.io.InputStreamReader;ImportJava.io.OutputStream;Importjava.net.HttpURLConnection;Importjava.net.MalformedURLException;ImportJava.net.URL;Importjava.net.URLConnection;Importjava.util.List;ImportJava.util.Map;ImportJava.net.URLEncoder; Public classSsrsdemo { Public Static voidMain (string[] args) {String URL= "Http://ipaddress/ReportServer?"; URL+ = Urlencoder.encode ("/tests/Test 2"); URL+ = "&rs:command=render&rs:format=pdf"; URL+ = "&p1=" +urlencoder.encode ("value of parameter 1") + "&p2=" +urlencoder.encode ("value of Parameter 2"); String FilePath= "C:/workspaces/java/limsreportservice/test"; FilePath+ = "/" + Java.util.UUID.randomUUID () + ". pdf";    DownloadFile (URL, filePath); }    /**     *      * @paramurlpath * Download Path *@paramdownloaddir * Download Storage path *@returnback to download file*/     Public Staticfile DownloadFile (string URLPath, String downloaddir) {File file=NULL; Try {            //Unified ResourcesURL url =NewURL (URLPath); //the parent class of the connection class, abstract classURLConnection URLConnection =url.openconnection (); //Connection classes for HTTPHttpURLConnection httpurlconnection =(httpurlconnection) URLConnection; //set the method of the request, default is getHttpurlconnection.setrequestmethod ("GET"); //Set character encodingHttpurlconnection.setrequestproperty ("Charset", "UTF-8"); //Open the communication link to the resource referenced by this URL if you have not already established such a connection. Httpurlconnection.connect ();//file nameString Filepathurl =Httpurlconnection.geturl (). GetFile (); String Filefullname= Filepathurl.substring (Filepathurl.lastindexof (File.separatorchar) + 1);urlconnection con=url.openconnection (); Bufferedinputstream bin=NewBufferedinputstream (Httpurlconnection.getinputstream ());File =NewFile (Downloaddir); if(!File.getparentfile (). exists ())            {File.getparentfile (). Mkdirs (); } OutputStream out=Newfileoutputstream (file); intSize = 0; intLen = 0; byte[] buf =New byte[1024];  while(size = Bin.read (BUF))! = 1) {len+=size; Out.write (BUF,0, size);            } bin.close ();        Out.close (); } Catch(malformedurlexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); } finally {            returnfile; }    }}

Java server-side build Report document: Using SQL Server Reporting Service (SSRS)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.