Pessoal estou aprendendo a fazer relatorios, já construi o aqrquivo xml com o irepport e coloqueio no mesmo pacote do arquivo que gera o pdf mas ele não o encontra, onde eu o coloco?
Arquivo xml
8 Respostas
posta todo codigo aqui menina !
package Relatorios;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.JasperViewer;
import java.sql.*;
import java.util.*;
/**
*
* @author Tarciana
*/
public class Relatorios_tentativa {
/* Realza contornan
iexão com o banco de dados, redo o objeto Connection */ private static Connection getConnection( ) throws
ClassNotFoundException, SQLException
{
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/BGN_DATE";
String user = "root";
String password = "1";
Class.forName(driver);
Connection con = DriverManager.getConnection( url, user, password );
return con;
}
/* Gera Relatorio e visualiza-o */
public void geraRelatorio( ) throws JRException, Exception
{
Connection con = getConnection( );
Statement stm = con.createStatement( );
String query = "select * from vendas";
ResultSet rs = stm.executeQuery( query );
/* implementação da interface JRDataSource para DataSource ResultSet */
JRResultSetDataSource jrRS = new JRResultSetDataSource( rs );
/* HashMap de parametros utilizados no relatório. Sempre instanciados */
Map parameters = new HashMap();
// parameters.put("COLUNA", valor);
// Preenche o relatório com os dados.
JasperFillManager.fillReportToFile( "tentativa.jasper", parameters, jrRS );
/* Exporta para o formato PDF */
JasperExportManager.exportReportToPdfFile( "tentativa.jrprint" );
/* Preenche o relatorio e o salva diretamente em arquivo PDF. Sem
a necessidade do .jrprint */
/* Visualiza o relatório em formato PDF */
JasperViewer.viewReport( "tentativa.pdf", false );
}
public static void main(String[] args) throws JRException, Exception
{
new Relatorios_tentativa().geraRelatorio();
}
}
Alguém responda, por favor…
aqrquivo xml cade o XML ?
Só pra deixar bem claro eu ainda estou aprendendo, e isso foi só um teste.
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="tentativa" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT * from vendas_produtos]]>
</queryString>
<field name="idVendas" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="idProdutos" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="preco" class="java.math.BigDecimal">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="quantidade" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="variable1" class="java.lang.String">
<variableExpression><![CDATA[$F{preco}.multiply( $F{quantidade} )]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="21" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{idVendas}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{idProdutos}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{preco}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$F{quantidade}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="400" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$V{variable1}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
BGN_DATE tem <variableExpression><![CDATA[$F{preco}.multiply( $F{quantidade} )]]></variableExpression> ?
Não, essa é uma variável que eu criei para multiplicar o preço pela quantidade, gerando o vaolor total… todo o xml tá dando certo no ireport, eu só estou encontrando dificuldade para fazer o netbeans encontrar o arquivo tentativa xml. Onde eu o coloco?
Olha a imagem !
