Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Java e Crystal Report

  1. #1
    Utente di HTML.it L'avatar di xrwnis
    Registrato dal
    Apr 2008
    Messaggi
    42

    Java e Crystal Report

    ciao a tutti. sono alle prese con java e crystal report 11 in ambiente netbeans. riesco a visualizzare un report con i dati presenti all'interno, quando invece vado a riempire il report con i dati presenti su un database viene fuori qst errore "errore nella ricerca del nome JNDI (nome server)". Il database che uso è sqlexpress 2008 r2.

    codice:
    import com.crystaldecisions.sdk.occa.report.lib.*;
    import javax.swing.*;
    
    public class JRCViewReportLogon {
    
    	private static final String REPORT_NAME = "C:\\lavoro\\report.rpt";
    
    	//Database credentials for the report's datasource.
    	private static final String USERNAME = "xx";
    	private static final String PASSWORD = "xxxx";
    
    	public static void launchApplication() {
    
    		try {
    			com.crystaldecisions.sdk.occa.report.application.ReportClientDocument reportClientDoc = new com.crystaldecisions.sdk.occa.report.application.ReportClientDocument();
    			reportClientDoc.open(REPORT_NAME, 0);
                            reportClientDoc.getDatabaseController().logon(USERNAME, PASSWORD);
    			new ReportViewerFrame(reportClientDoc);
    
    		}
    		catch(ReportSDKException ex) {
    			System.out.println(ex);
    		}
    		catch(Exception ex) {
    			System.out.println(ex);
    		}
    
    	}
    
    	public static void main(String [] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				launchApplication();
    			}
    		});
    
    	}
    
    }
    
    import com.crystaldecisions.sdk.occa.report.lib.*;
    import com.crystaldecisions.ReportViewer.*;
    
    //Java imports.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class ReportViewerFrame extends JFrame {
    
    	//Initial window frame properties.
    	private final int XPOS = 75;
    	private final int YPOS = 50;
    	private final int WIDTH = 750;
    	private final int HEIGHT = 600;
    
    	//Crystal Report thick-client viewer object that will be embedded into the JFrame.
    	private ReportViewerBean reportViewer = new ReportViewerBean();
    	//This report will be viewed in the thick-client viewer.
    	private com.crystaldecisions.sdk.occa.report.application.ReportClientDocument reportClientDoc = new com.crystaldecisions.sdk.occa.report.application.ReportClientDocument();
    
    	/**
    	 * Constructs and launches the new frame.
    	 */
    	public ReportViewerFrame(com.crystaldecisions.sdk.occa.report.application.ReportClientDocument reportClientDoc) throws Exception {
    
    		//Initialize frame properties.
    		this.setResizable(true);
    		this.setLocation(XPOS, YPOS);
    		this.setSize(WIDTH, HEIGHT);
    		this.setTitle("Crystal Report Java Viewer");
    
    		//Add GUI components to the frame including the ReportViewerBean.
    		addComponents();
    
    		//Add GUI listeners to the frame.
    		addListeners();
    
    		//Set the report that the ReportViewerBean will display.
    		this.reportClientDoc = reportClientDoc;
    		reportViewer.setReportSource(reportClientDoc.getReportSource());
    		reportViewer.init();
    		reportViewer.start();
    
    		//Display the frame.
    		this.setVisible(true);
    
    	}
    
    	/**
    	 * Utility function for adding GUI components to frame.  Created to separate
    	 * the constructor logic of the frame from logic for adding visual
    	 * components.  This function will add the ReportViewerBean to the frame.
    	 */
    	private void addComponents() {
    
    	  	//Create new panel and add the ReportViewerBean to it.
    		Container cp = getContentPane();
    		cp.setLayout(new BorderLayout());
    		cp.add(reportViewer);
    
    	}
    
    	/**
    	 * Utility function for adding GUI listeners to the frame.  Created to separate
    	 * the constructor logic of the frame for adding listeners.
    	 */
    	private void addListeners() {
    
    		//This window listener will capture the event of the ReportViewerFrame being closed.  If this
    		//frame is closed, then it is a good practice to then close the report being displayed, which the
    		//quit() method will handle.
    		addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				quit();
    			}
    		});
    
    	}
    
    	/**
    	 * Close frame and report being viewed.
    	 */
    	public void quit() {
    
    	  	try {
    	  		//Release report.
    	  		reportClientDoc.close();
    			System.exit(0);
    	  	}
    	  	catch(ReportSDKException ex) {
    	  		ex.printStackTrace();
    	  	}
    
    	}
    }
    sono due classi che ho trovato sul web e ho cambiato semplicemente i dati relativi al database. qualche idea? Grazie in anticipo.

  2. #2
    Ciao, io devo iniziare con Crystal report e Netbeans, mi consiglieresti dove posso fare il download delle librerie per Netbeans?

  3. #3
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,480

    Moderazione

    Originariamente inviato da sistem3
    Ciao, io devo iniziare con Crystal report e Netbeans, mi consiglieresti dove posso fare il download delle librerie per Netbeans?
    Non risollevare discussioni vecchie per porre altre domande, senza contare che hai già aperto una discussione in proposito qui, quindi continua questa.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.