Dificuldade para imprimir relatorio com o ireport

1 resposta
D

Olá pessoal , boa noite.

Pessoal estou tendo dificuldade para utilizar um relatorio com o ireport. Criei um programa aqui na empresa para controle de estoque. São apenas 18 campos. Eu estou utilizando o banco mysql. O programa está cadastrando e consultado normalmente, só que nunca utilizei o ireport para exibir relatório.
Eu gostaria e exibir o relatorio do banco , como faço ? Obs: o programa é de uso local em um servidor mysql
Segue o codigo do programa.

AQUI É O PROGRAMA

package atendimentosac;

import java.sql.*;

import javax.swing.JFormattedTextField;

import javax.swing.JOptionPane;

import javax.swing.text.MaskFormatter;

public class SacGui extends javax.swing.JFrame {

BancoSac bancoSac = new BancoSac();

BancoRma bancorma = new BancoRma();

BancoEnvio bancoenvio = new BancoEnvio();

BancoPend bancopend = new BancoPend();

BancoEstoque bancoestoque = new BancoEstoque();

AQUI ESTOU INSTANCIANDO A CLASSE CONEXÃOJASPER

conexaoJasper conexaojasper = new conexaoJasper();
public SacGui() {
    initComponents();
   // controle();
    }
public MaskFormatter Mascara(String Mascara) {

    MaskFormatter F_Mascara = new MaskFormatter();
    try {
        F_Mascara.setMask(Mascara);   
        F_Mascara.setPlaceholderCharacter(' ');    
    } catch (Exception excecao) {
        excecao.printStackTrace();
    }
 return F_Mascara;
}
public void conexaoreport(){

}

public void limpapendente(){

txtPendRma.setText("");

txtPendNome.setText("");

txtPendTelefone.setText("");

txtPendCpf.setText("");

txtPendEquipamento.setText("");

cboPendAssistencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “”, D-Link Brasil, GRS7, D.Repair Cursino, D.Repair Timbiras, Infocell, Fix Center, Tex Tel, LW INFO, 3 Way, CHLB, Soma }));

txtPendEntrada.setText("");

txtPendAbertura.setText("");

txtPendStatusEquipamento.setText("");

cboPendFormaEnvio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “”, Sedex, Sedex à cobrar, Envio comum, Balcão, Transportadora }));

}

public void limpaRma(){

txtRma.setText("");

txtRmaNome.setText("");

txtRmaContato.setText("");

txtRmaEquipamento.setText("");

txtRmaEntrada.setText("");

txtRmaDataContato.setText("");

cboRmaStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “”, Conferido, Pendente (peça), Análise técnica }));

txtRmaAtendente.setText("");

txtRmaObservacao.setText("");

}

public void limpaEnvioComponente(){

txtEnvioCodigo.setText("");

txtEnvioNome.setText("");

txtEnvioCpf.setText("");

txtEnvioEmail.setText("");

txtEnvioRua.setText("");

txtEnvioNumero.setText("");

txtEnvioCompl.setText("");

txtEnvioBairro.setText("");

txtEnvioCidade.setText("");

txtEnvioEstado.setText("");

txtEnvioCep.setText("");

txtEnvioTelefone.setText("");

txtEnvioComponente.setText("");

txtEnvioVoltagem.setText("");

txtEnvioAmper.setText("");

txtEnvioDescricao.setText("");

}

public void limpaAtendimento(){

txtAtendimentoRma.setText("");

txtAtendimentoNome.setText("");

txtAtendimentoTelefone.setText("");

txtAtendimentoEmail.setText("");

txtAtendimentoCpf.setText("");

txtAtendimentoSerie.setText("");

txtAtendimentoEquipamento.setText("");

cboAtendimentoAssistencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “”, D-Link Brasil, GSR7, D.Repair Cursino, D.Repair Timbiras, Infocell, Fix Center, Tex Tel, LW INFO, 3 Way, CHLB, Soma }));

txtAtendimentoAbertura.setText("");

txtAtendimentoEntrada.setText("");

txtAtendimentoStatus.setText("");

}

public void limpaEstoque(){

txtEstoqueCod.setText("");

txtEstoqueDsl500g.setText("");

txtEstoqueDsl500b.setText("");

txtEstoqueDi524.setText("");

txtEstoqueDi604.setText("");

txtEstoqueDi624.setText("");

txtEstoqueDwlG730.setText("");

txtEstoqueDes1008D.setText("");

txtEstoque1008DDemais.setText("");

txtEstoqueDsl500g.setText("");

txtEstoqueAntena.setText("");

txtEstoqueCaboRJ45.setText("");

txtEstoqueCaboRj11.setText("");

txtEstoqueCaboUsb.setText("");

txtEstoqueFiltroLinha.setText("");

txtEstoqueDerivador.setText("");

txtEstoquePezinho.setText("");

txtEstoqueCd.setText("");

txtEstoqueManuais.setText("");
}

public void consultarAtendimento(){

int rma = Integer.parseInt(JOptionPane.showInputDialog(null, Digite o RMA));

String nome = bancoSac.consultar(rma, 2);

String telefone = bancoSac.consultar(rma, 3);

String email = bancoSac.consultar(rma, 4);

String cpf = bancoSac.consultar(rma, 5);

String equipamento = bancoSac.consultar(rma, 6);

String serie = bancoSac.consultar(rma, 7);

String assistencia = bancoSac.consultar(rma, 8);

String abertura = bancoSac.consultar(rma, 9);

String entrada = bancoSac.consultar(rma, 10);

String status = bancoSac.consultar(rma,11);
txtAtendimentoRma.setText(String.valueOf(rma));
    txtAtendimentoNome.setText(nome);
    txtAtendimentoTelefone.setText(telefone);
    txtAtendimentoCpf.setText(cpf);
    txtAtendimentoEmail.setText(email);
    txtAtendimentoEquipamento.setText(equipamento);
    txtAtendimentoSerie.setText(serie);
    cboAtendimentoAssistencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { assistencia , "D-Link Brasil", "GSR7" ,"D.Repair Cursino", "D.Repair Timbiras", "Infocell", "Fix Center", "Tex Tel", "LW INFO", "3 Way", "CHLB", "Soma" }));
    txtAtendimentoAbertura.setText(abertura);
    txtAtendimentoEntrada.setText(entrada);
    txtAtendimentoStatus.setText(status);
    
}
public void consultarEnvio (){
    int codigo = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite o Protocolo"));
    String nome = bancoenvio.consultar(codigo, 2);
    String cpf = bancoenvio.consultar(codigo, 3);
    String email = bancoenvio.consultar(codigo, 4);
    String rua = bancoenvio.consultar(codigo, 5);
    String numero = bancoenvio.consultar(codigo, 6);
    String complemento = bancoenvio.consultar(codigo, 7);
    String bairro = bancoenvio.consultar(codigo, 8);
    String cidade = bancoenvio.consultar(codigo, 9);
    String estado = bancoenvio.consultar(codigo, 10);
    String cep = bancoenvio.consultar(codigo, 11);
    String telefone = bancoenvio.consultar(codigo, 12);
    String componente = bancoenvio.consultar(codigo, 13);
    String amperagem = bancoenvio.consultar(codigo, 14);
    String voltagem = bancoenvio.consultar(codigo, 15);
    String descricao = bancoenvio.consultar(codigo, 16);
    
    txtEnvioCodigo.setText(String.valueOf(codigo));
    txtEnvioNome.setText(nome);
    txtEnvioCpf.setText(cpf);
    txtEnvioEmail.setText(email);
    txtEnvioRua.setText(rua);
    txtEnvioNumero.setText(numero);
    txtEnvioCompl.setText(complemento);
    txtEnvioBairro.setText(bairro);
    txtEnvioCidade.setText(cidade);
    txtEnvioEstado.setText(estado);
    txtEnvioCep.setText(cep);
    txtEnvioTelefone.setText(telefone);
    txtEnvioComponente.setText(componente);
    txtEnvioVoltagem.setText(amperagem);
    txtEnvioAmper.setText(voltagem);
    txtEnvioDescricao.setText(descricao);
 }
   
   public void consultarRma (){
   int rma = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite o RMA"));
   String nome = bancorma.consultar(rma, 2); 
   String contato = bancorma.consultar(rma, 3);
   String equipamento = bancorma.consultar(rma, 4);
   String entrada = bancorma.consultar(rma, 5);
   String abertura = bancorma.consultar(rma, 6);
   String status = bancorma.consultar(rma, 7);
   String atendente = bancorma.consultar(rma, 8);
   String obs = bancorma.consultar(rma, 9);
   
   txtRma.setText(String.valueOf(rma));
   txtRmaNome.setText(nome);
   txtRmaContato.setText(contato);
   txtRmaEquipamento.setText(equipamento);
   txtRmaEntrada.setText(entrada);
   txtRmaDataContato.setText(abertura);
   cboRmaStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { status, "Conferido", "Pendente (peça)", "Análise Técnica" }));
   txtRmaAtendente.setText(atendente);
   txtRmaObservacao.setText(obs);
 }
 public void consultarPendente (){
    int rma = Integer.parseInt(JOptionPane.showInputDialog(null, "Digite o RMA"));
    String nome = bancopend.consultar(rma, 2);
    String telefone = bancopend.consultar(rma, 3);
    String cpf = bancopend.consultar(rma, 4);
    String equipamento = bancopend.consultar(rma, 5);
    String assistencia = bancopend.consultar(rma, 6);
    String abertura = bancopend.consultar(rma, 7);
    String entrada = bancopend.consultar(rma, 8);
    String forma_envio = bancopend.consultar(rma, 9);
    String status = bancopend.consultar(rma, 10);
    
    txtPendRma.setText(String.valueOf(rma));
    txtPendNome.setText(nome);
    txtPendTelefone.setText(telefone);
    txtPendCpf.setText(cpf);
    txtPendEquipamento.setText(equipamento);
    cboPendAssistencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { assistencia, "D-Link Brasil", "GSR7" ,"D.Repair Cursino", "D.Repair Timbiras", "Infocell", "Fix Center", "Tex Tel", "LW INFO", "3 Way", "CHLB", "Soma" }));
    txtPendAbertura.setText(abertura);
    txtPendEntrada.setText(entrada);
    cboPendFormaEnvio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { forma_envio, "Sedex", "Sedex à cobrar", "Envio comum", "Balcão", "Transportadora" }));
    txtPendStatusEquipamento.setText(status);
}
AQUI ESTOU CHAMANDO O MEDOTO QUE CONSULTA NO BANCO

public void consultarEstoque (){

int codigo = Integer.parseInt(JOptionPane.showInputDialog(null, Digite o Componente));

String dsl500g = bancoestoque.consultar(codigo, 2);

String dsl500b = bancoestoque.consultar(codigo, 3);

String di524 = bancoestoque.consultar(codigo, 4);

String di604 = bancoestoque.consultar(codigo, 5);

String di624 = bancoestoque.consultar(codigo, 6);

String dwlg730 = bancoestoque.consultar(codigo, 7);

String des1008d = bancoestoque.consultar(codigo, 8);

String des1008dd = bancoestoque.consultar(codigo, 9);

String antena = bancoestoque.consultar(codigo, 10);

String cabo_rj45 = bancoestoque.consultar(codigo, 11);

String cabo_rj11 = bancoestoque.consultar(codigo, 12);

String cabo_usb = bancoestoque.consultar(codigo, 13);

String filtro_Linha = bancoestoque.consultar(codigo, 14);

String derivador = bancoestoque.consultar(codigo, 15);

String pezinho = bancoestoque.consultar(codigo, 16);

String cd = bancoestoque.consultar(codigo, 17);

String manuais = bancoestoque.consultar(codigo, 18);
txtEstoqueCod.setText(String.valueOf(codigo));
    txtEstoqueDsl500g.setText(dsl500g);
    txtEstoqueDsl500b.setText(dsl500b);
    txtEstoqueDi524.setText(di524);
    txtEstoqueDi604.setText(di604);
    txtEstoqueDi624.setText(di624);
    txtEstoqueDwlG730.setText(dwlg730);
    txtEstoqueDes1008D.setText(des1008d);
    txtEstoque1008DDemais.setText(des1008dd);
    txtEstoqueAntena.setText(antena);
    txtEstoqueCaboRJ45.setText(cabo_rj45);
    txtEstoqueCaboRj11.setText(cabo_rj11);
    txtEstoqueCaboUsb.setText(cabo_usb);
    txtEstoqueFiltroLinha.setText(filtro_Linha);
    txtEstoqueDerivador.setText(derivador);
    txtEstoquePezinho.setText(pezinho);
    txtEstoqueCd.setText(cd);
    txtEstoqueManuais.setText(manuais);

}

private void jFormattedTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                                     

}                                                    

private void jFormattedTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                                     

}                                                    

private void rrrFocusLost(java.awt.event.FocusEvent evt) {

}

private void bntPendenteConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                                     
consultarPendente ();    
}                                                    

private void bntAtendimentoSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                                     
    String rma = txtAtendimentoRma.getText();
    String nome = txtAtendimentoNome.getText();
    String telefone = txtAtendimentoTelefone.getText();
    String email = txtAtendimentoEmail.getText();
    String cpfX = txtAtendimentoCpf.getText();
    long cpf = Long.parseLong(cpfX);
    String equipamento = txtAtendimentoEquipamento.getText();
    String serie = txtAtendimentoSerie.getText();
    String assistencia = String.valueOf(cboAtendimentoAssistencia.getSelectedItem());
    String abertura = txtAtendimentoAbertura.getText();
    String entrada = txtAtendimentoEntrada.getText();
    String status = txtAtendimentoStatus.getText();
    bancoSac.incluir(rma, nome, telefone, email, cpf, equipamento, serie, assistencia, abertura, entrada, status);
    limpaAtendimento();
}                                                    
 
private void btnAtendimentoLimparActionPerformed(java.awt.event.ActionEvent evt) {                                                     
limpaAtendimento();

}

private void btnPendenteLimparActionPerformed(java.awt.event.ActionEvent evt) {                                                  
limpapendente();

}

private void btnEnvioLimparActionPerformed(java.awt.event.ActionEvent evt) {                                               
limpaEnvioComponente();

}

private void btnRmaLimparActionPerformed(java.awt.event.ActionEvent evt) {                                             
limpaRma();

}

private void formWindowActivated(java.awt.event.WindowEvent evt) {                                     
    
}                                    

private void formWindowIconified(java.awt.event.WindowEvent evt) {                                     
   
}                                    

private void formWindowStateChanged(java.awt.event.WindowEvent evt) {                                        
  
}                                       

private void txtEnvioTelefoneActionPerformed(java.awt.event.ActionEvent evt) {                                                 
   
}                                                

private void txtEnvioComponenteActionPerformed(java.awt.event.ActionEvent evt) {

}

private void txtAtendimentoRmaActionPerformed(java.awt.event.ActionEvent evt) {                                                  
   
}                                                 

private void bntEnvioSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                               
    String protocolo = txtEnvioCodigo.getText();
    String nome = txtEnvioNome.getText();
    String cpfS = txtEnvioCpf.getText();
    long cpf = Long.parseLong(cpfS);
    String email = txtEnvioEmail.getText();
    String rua = txtEnvioRua.getText();
    String numero = txtEnvioNumero.getText();
    String complemento = txtEnvioCompl.getText();
    String bairro = txtEnvioBairro.getText();
    String cidade = txtEnvioCidade.getText();
    String estado = txtEnvioEstado.getText();
    String cep = txtEnvioCep.getText(); 
    String telefone = txtEnvioTelefone.getText();
    String componente = txtEnvioComponente.getText();
    String amperagem = txtEnvioAmper.getText();
    String voltagem = txtEnvioVoltagem.getText();
    String descricao = txtEnvioDescricao.getText();
    bancoenvio.incluir(protocolo, nome, cpf, email, rua, numero, complemento, bairro, cidade, estado, cep, telefone, componente, amperagem, voltagem, descricao);
    limpaEnvioComponente();
}                                              

private void txtEnvioCodigoActionPerformed(java.awt.event.ActionEvent evt) {                                               
  
}                                              

private void txtEnvioNomeActionPerformed(java.awt.event.ActionEvent evt) {                                             
    
}                                            

private void txtEnvioCpfActionPerformed(java.awt.event.ActionEvent evt) {                                            
   
}                                           

private void txtEnvioEmailActionPerformed(java.awt.event.ActionEvent evt) {                                              
    
}                                             

private void txtEnvioAmperActionPerformed(java.awt.event.ActionEvent evt) {                                              
    
}                                             

private void bntSacSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                             
    String rma = txtRma.getText();
    String nome = txtRmaNome.getText();
    String contato = txtRmaContato.getText();
    String equipamento = txtRmaEquipamento.getText();
    String entrada = txtRmaEntrada.getText();
    String abertura = txtRmaDataContato.getText();
    String status = String.valueOf(cboRmaStatus.getSelectedItem());
    String atendente = txtRmaAtendente.getText();
    String obs = txtRmaObservacao.getText();
    
    bancorma.incluir(rma, nome, contato, equipamento, entrada, abertura, status, atendente, obs);
    limpaRma();
}                                            

private void bntEnvioExcluirActionPerformed(java.awt.event.ActionEvent evt) {                                                

}                                               

private void bntPendenteSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    String rma = txtPendRma.getText();
    String nome = txtPendNome.getText();
    String telefone = txtPendTelefone.getText();
    String cpfS = txtPendCpf.getText();
    long cpf = Long.parseLong(cpfS);
    String equipamento = txtPendEquipamento.getText();
    String assistencia = String.valueOf(cboPendAssistencia.getSelectedItem());
    String abertura = txtPendAbertura.getText();
    String entrada = txtPendEntrada.getText();
    String forma_envio = String.valueOf(cboPendFormaEnvio.getSelectedItem());
    String status = txtPendStatusEquipamento.getText();
    
    bancopend.incluir (rma, nome, telefone, cpf, equipamento, assistencia, entrada, abertura, forma_envio, status);
    limpapendente();
}                                                 

private void txtPendRmaActionPerformed(java.awt.event.ActionEvent evt) {                                           
    
}                                          

private void txtPendNomeActionPerformed(java.awt.event.ActionEvent evt) {                                            
    
}                                           

private void txtPendCpfActionPerformed(java.awt.event.ActionEvent evt) {                                           
    
}                                          

private void cboAtendimentoAssistenciaActionPerformed(java.awt.event.ActionEvent evt) {

}

private void txtAtendimentoSerieActionPerformed(java.awt.event.ActionEvent evt) {                                                    
    
}                                                   

private void txtAtendimentoCpfActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    

}                                                 

private void txtEnvioRuaActionPerformed(java.awt.event.ActionEvent evt) {

}

private void bntAtendimentoConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                                        
    consultarAtendimento();
}                                                       

private void txtEstoqueDsl500bActionPerformed(java.awt.event.ActionEvent evt) {

}

private void txtEstoqueDsl500gActionPerformed(java.awt.event.ActionEvent evt) {

}

private void txtEstoqueDi624ActionPerformed(java.awt.event.ActionEvent evt) {

}

private void txtEstoqueDi524ActionPerformed(java.awt.event.ActionEvent evt) {
}

AQUI É O MÉTODO NO BOTÃO QUE ENVIA OS DADOS PARA O BANCO DE DADOS

private void bntEstoqueSalvarActionPerformed(java.awt.event.ActionEvent evt) {

String codigo = txtEstoqueCod.getText();

String dsl500g  = txtEstoqueDsl500g.getText();

String dsl500b = txtEstoqueDsl500b.getText();

String di524 = txtEstoqueDi524.getText();

String di604= txtEstoqueDi604.getText();

String di624 = txtEstoqueDi624.getText();

String dwlg730 = txtEstoqueDwlG730.getText();

String des1008d =  txtEstoqueDes1008D.getText();

String des1008dd = txtEstoque1008DDemais.getText();

String antena = txtEstoqueAntena.getText();

String cabo_rj45 = txtEstoqueCaboRJ45.getText();

String cabo_rj11 = txtEstoqueCaboRj11.getText();

String cabo_usb  = txtEstoqueCaboUsb.getText();

String filtro_Linha = txtEstoqueFiltroLinha.getText();

String derivador = txtEstoqueDerivador.getText();

String pezinho = txtEstoquePezinho.getText();

String cd = txtEstoqueCd.getText();

String manuais = txtEstoqueManuais.getText();
bancoestoque.incluir (codigo, dsl500g, dsl500b, di524, di604, di624, dwlg730, des1008d, des1008dd, antena, cabo_rj45, cabo_rj11, cabo_usb, filtro_Linha, derivador, pezinho, cd, manuais);
    limpaEstoque();
}                                                

private void bntEstoqueConsultarActionPerformed(java.awt.event.ActionEvent evt) {
AQUI É A FUNÇÃO QUE CHAMA O MÉTODO QUE CONSULTA NO BANCO DE DADOS

consultarEstoque();

}
private void btnEstoqueLimparActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    limpaEstoque();
}                                                

private void cboRmaStatusActionPerformed(java.awt.event.ActionEvent evt) {                                             
    
}                                            

private void bntEnvioConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    consultarEnvio();
}                                                 

private void bntSacConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                                
    consultarRma();
}                                               

private void txtRmaActionPerformed(java.awt.event.ActionEvent evt) {                                       
   
}                                      

private void cboPendAssistenciaActionPerformed(java.awt.event.ActionEvent evt) {                                                   
    
}                                                  

private void bntEnvioImprimirActionPerformed(java.awt.event.ActionEvent evt) {                                                 

} 
private void bntEstoqueImprimirActionPerformed(java.awt.event.ActionEvent evt) {
 [b] AQUI É O BOTÃO IMPRIMIR DO PROGRAMA. GOSTARIA DE SABER COMO FAÇO PRA CHAMAR O RELATORIO QUANDO O BOTÃO FOR CLICADO.[/b]
}                                               
public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new SacGui().setVisible(true);
        }
    });

}
// Variables declaration - do not modify                     
private javax.swing.JButton bntAtendimentoAlterar;
private javax.swing.JButton bntAtendimentoConsultar;
private javax.swing.JButton bntAtendimentoExcluir;
private javax.swing.JButton bntAtendimentoImprimir;
private javax.swing.JButton bntAtendimentoSalvar;
private javax.swing.JButton bntEnvioAlterar;


// End of variables declaration

}


SEGUE A CLASSE DE CONEXÃO COM O JASPER

package atendimentosac;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.HashMap;

import java.util.Map;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JRResultSetDataSource;

import net.sf.jasperreports.engine.JasperCompileManager;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.JasperReport;

import net.sf.jasperreports.engine.design.JasperDesign;

import net.sf.jasperreports.engine.xml.JRXmlLoader;

import net.sf.jasperreports.view.JasperViewer;

public class conexaoJasper {

private static final String url = "jdbc:mysql://127.0.0.1/bancosac";
private static final String driver = "com.mysql.jdbc.Driver";
private static final String login = "root";
private static final String pwd = "";
public conexaoJasper() {
}
public void gerar( String layout ) throws JRException , SQLException, ClassNotFoundException {
	//gerando o jasper design
	JasperDesign desenho = JRXmlLoader.load( layout );
	//compila o relatório
	JasperReport relatorio = JasperCompileManager.compileReport( desenho );
	//estabelece conexão
	Class.forName( driver );
	Connection con = DriverManager.getConnection( url , login , pwd );
	Statement stm = con.createStatement();
	String query = "select * from Sac_envio";
	ResultSet rs = stm.executeQuery( query );
	//implementação da interface JRDataSource para DataSource ResultSet
	JRResultSetDataSource jrRS = new JRResultSetDataSource( rs );
	//executa o relatório
	Map parametros = new HashMap();
	parametros.put("nota", new Double(10));
	JasperPrint impressao = JasperFillManager.fillReport( relatorio , parametros,    jrRS );
	//exibe o resultado
	JasperViewer viewer = new JasperViewer( impressao , true );
	viewer.show();
}
public static void main(String[] args) {
	try {
		new conexaoJasper().gerar( "sac.jrxml" );
	} catch (Exception e) {
		e.printStackTrace();
	}
}

}

1 Resposta

paulo.ubuntu

Opa.

Então
tenho duas coisas a lhe dizer

1º - O Seu código está definitivamente horrivel de entender… coloque entre as tags CODE na hora de postar que facilita a tua vida e a nossa tambem.

2º - logo de cara… pelo pouco que entendi… voce ta tentando gerar o relatório a partir do jrxml (Jasper Reports XML), sendo que o certo seria .jasper
que é o compilado

acho que esse video pode te ajudar um pouco ok ?

Abraços

Criado 21 de abril de 2008
Ultima resposta 21 de abr. de 2008
Respostas 1
Participantes 2