free576002 Posted January 13, 2016 Posted January 13, 2016 I want use sql command how I to do ?this's is my code and I can read pdf from<%@ page contentType="application/pdf" %><%@ page trimDirectiveWhitespaces="true"%><%@ page import="net.sf.jasperreports.engine.*" %><%@ page import="java.io.File" %><%@ page import="java.io.FileInputStream" %><%@ page import="java.io.FileNotFoundException" %><%@ page import="java.io.InputStream" %><%@ page import="java.sql.Connection" %><%@ page import="java.sql.DriverManager" %><%@ page import="java.sql.SQLException" %> <% Connection conn=null; try { //Connecting to the MySQL Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=passwd1234"); String jrxmlFile = session.getServletContext().getRealPath(request.getContextPath())+"/T0113.jrxml"; System.out.println("Check file path : "+jrxmlFile); InputStream input = new FileInputStream(new File(jrxmlFile)); JasperReport jasperReport = JasperCompileManager.compileReport(input); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (JRException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if(conn!=null){ conn.close(); } }%>
hozawa Posted January 14, 2016 Posted January 14, 2016 The usual way is to just write sql command in your jrxml file but you can try passing sql statement as a parameter.
christopher.g.kennedy Posted January 14, 2016 Posted January 14, 2016 Hi, To add/update a query in studio: use the data set and query editor dialog to the left of the + and - hourglass buttons top center of the design view main report window. For iReports, use the "Report Query" Button, in the Designer view. The button is to the right of preview. if you review the jrxml source, your query will look like the following: <queryString> <![CDATA[sELECT ... FROM ... JOIN ... ON ... LEFT OUTER JOIN ... ON ... WHERE RVL.VISIT_DATE >= $P{Begin} AND RVL.VISIT_DATE <= $P{End} AND RVL.REGION = $P{Region} ORDER BY RVL.REGION, ...]]> I hope this helps, Chris Kennedy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now