I wnat add sql command inside jsp

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();
        }
    }
%>
free576002's picture
Joined: Jan 11 2016 - 9:04pm
Last seen: 6 years 1 month ago

2 Answers:

The usual way is to just write sql command in your jrxml file but you can try passing sql statement as a parameter.

hozawa's picture
125858
Joined: Apr 24 2010 - 4:31pm
Last seen: 2 years 11 months ago
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
 
christopher.g.kennedy's picture
Joined: Mar 18 2015 - 1:10pm
Last seen: 5 years 6 months ago
Feedback
randomness