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)