RISOLTO Upgrade crystal report e componenti activex

Stato
Discussione chiusa ad ulteriori risposte.

Skills07

Head of Development
Staff Forum
Utente Èlite
35,447
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
di solito in java si deve scaricare il driver del db(jdbc, odbc, etc) e creare una connection tramite questo driver.
Una volta creata la connessione al db, fare delle query che tirano fuori i dati che ti servono.

https://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

leggi qui, in tal caso contattami ancora che ti aiuto.
 
  • Mi piace
Reazioni: Scripta14

Scripta14

Nuovo Utente
95
8
ciao, ci ho lavorato e sono riuscito a stabilire la connessione o quantomeno in parte,e c'è ancora qualcosa che mi sfugge.
Siccome ho due diverse connessione una in Oracle e l'altra in Access. La prima riesco a generare il pdf, peccato che mi genera un file con un foglio bianco:boh::boh:, mentre la seconda connessione mi esce il messaggio:
"ERROR com.businessobjects.reports.sdk.JRCCommunicationAdapter - detected an exception: Errore imprevisto del connettore del database".
ti riporto il codice di entrambi.
Commessione Oracle
Codice:
public class JavaConnectionOracle {
     
    private static Connection dbcon = null;
    private Statement stmt = null;
    private static ResultSet rs = null;

    public static void main(String[] args) {
        String connURL = "jdbc:oracle:thin:@NOMESERVER:PORT:SID";
        String dataBaseClassName="oracle.jdbc.driver.OracleDriver";
        String userURL = NOMEUTENTE;
        String passURL = PASSWORD;
         PropertyBag propertyBag = null;
         IConnectionInfo connectionInfo = null;
         ITable origTable = null;
         ITable newTable = null;
         String TRUSTED_CONNECTION = "false";
         String SERVER_TYPE = "JDBC (JNDI)";
         String USE_JDBC = "true";
         String DATABASE_DLL = "crdb_jdbc.dll";
         String theFile="C:\\ProveCR2013\\ReportOracle.rpt";
         String EXPORT_FILE = "C:\\ProveCR2013\\myExportedReport.pdf";
         String tableName=null;
         
         BasicConfigurator.configure();
        
          try {
              Class.forName(dataBaseClassName);
              } catch (ClassNotFoundException ex) {
                      System.out.println(ex.getMessage());
              }
          //Create the connection using the static getConnection method
              try {
              dbcon = DriverManager.getConnection (connURL, userURL, passURL);
              if(dbcon.isValid(10)) 
                  System.out.println("connessione ancora aperta");
              else 
                  System.out.println("connessione chiusa");
              
           
              
              ReportClientDocument rcd=new ReportClientDocument();
              rcd.open(theFile, OpenReportOptions._openAsReadOnly);
              Tables tables = rcd.getDatabaseController ().getDatabase ().getTables ();   
              System.out.println("Dimensione della tabella "+tables.size());
              for (int i = 0; i < tables.size (); i++)
              {
                  origTable = tables.getTable (i);
                  System.out.println(" origTable "+origTable.getName());
                  if (tableName == null || origTable.getName ().equals (tableName))
                  {
                      newTable = (ITable) origTable.clone (true);
                      newTable.setQualifiedName (origTable.getAlias ());
                   // Change connection information properties
                      connectionInfo = newTable.getConnectionInfo ();

                      // Set new table connection property attributes
                      propertyBag = new PropertyBag ();
                      

                      // Overwrite any existing properties with updated values
                      propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                      propertyBag.put ("Server Type", SERVER_TYPE);
                      propertyBag.put ("Use JDBC", USE_JDBC);
                      propertyBag.put ("Database DLL", DATABASE_DLL);
                      propertyBag.put ("Connection URL", connURL);
                      propertyBag.put ("Database Class Name", dataBaseClassName);
                      connectionInfo.setAttributes (propertyBag);
                      connectionInfo.setUserName (userURL);
                      connectionInfo.setPassword (passURL);
                   // Update the table information
                      rcd.getDatabaseController ().setTableLocation (origTable, newTable);
                  //   tableName=newTable.getName();
                 //     rcd.getDatabaseController ().setDataSource (rs, tableName, tableName + "_ResultSet");
                      
                  }
              }
              
              
              System.out.println("name new Table "+newTable.getName());
           
              
              ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
              
//            //Release report.
            rcd.close();
              
          //Use the Java I/O libraries to write the exported content to the file system.
            byte byteArray[] = new byte[byteArrayInputStream.available()];

            //Create a new file that will contain the exported result.
            File file = new File(EXPORT_FILE);
            FileOutputStream fileOutputStream = new FileOutputStream(file);

            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
            int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

            byteArrayOutputStream.write(byteArray, 0, x);
            byteArrayOutputStream.writeTo(fileOutputStream);

            //Close streams.
            byteArrayInputStream.close();
            byteArrayOutputStream.close();
            fileOutputStream.close();
            
            System.out.println("Successfully exported report to " + EXPORT_FILE);
              
      } catch (SQLException ex) {
              System.out.println(ex.getMessage());
      } catch (ReportSDKException e) {
        System.out.println(e.getMessage());
        
     }
    catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    
    }

}

Mentre la connessione Access
Codice:
public class JavaConnectionAccess {
     
    private static Connection dbcon = null;
    private Statement stmt = null;
    private static ResultSet rs = null;

    public static void main(String[] args) {
        String connURL = "jdbc:ucanaccess://C://TMP//DBACCESS.mdb";
       // String dataBaseClassName="sun.jdbc.odbc.JdbcOdbcDriver";
       
         PropertyBag propertyBag = null;
         IConnectionInfo connectionInfo = null;
         ITable origTable = null;
         ITable newTable = null;
         String TRUSTED_CONNECTION = "false";
         String SERVER_TYPE = "JDBC (JNDI)";
         String USE_JDBC = "true";
         String DATABASE_DLL = "crdb_jdbc.dll";
        // String theFile="C:\\ProveCR2013\\ReportOracle.rpt";
         String theFile="C:\\ProveCR2013\\st_rpt_11.rpt";
         String EXPORT_FILE = "C:\\ProveCR2013\\myExportedReport.pdf";
         String tableName=null;
         
         BasicConfigurator.configure();
        
    
             
          //Create the connection using the static getConnection method
              try {
              dbcon = DriverManager.getConnection (connURL);
              if(dbcon.isValid(10)) 
                  System.out.println("connessione ancora aperta");
              else 
                  System.out.println("connessione chiusa");
              
           
              
              ReportClientDocument rcd=new ReportClientDocument();
              rcd.open(theFile, OpenReportOptions._openAsReadOnly);
              Tables tables = rcd.getDatabaseController ().getDatabase ().getTables ();   
              
              System.out.println("Dimensione della tabella "+tables.size());
             
              
              for (int i = 0; i < tables.size (); i++)
              {
                  origTable = tables.getTable (i);
                  System.out.println(" origTable "+origTable.getName());
                  if (tableName == null || origTable.getName ().equals (tableName))
                  {
                      newTable = (ITable) origTable.clone (true);
                      newTable.setQualifiedName (origTable.getAlias ());
                   // Change connection information properties
                      connectionInfo = newTable.getConnectionInfo ();

                      // Set new table connection property attributes
                      propertyBag = new PropertyBag ();
                      

                      // Overwrite any existing properties with updated values
                      propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                      propertyBag.put ("Server Type", SERVER_TYPE);
                      propertyBag.put ("Use JDBC", USE_JDBC);
                      propertyBag.put ("Database DLL", DATABASE_DLL);
                      propertyBag.put ("Connection URL", connURL);
                     // propertyBag.put ("Database Class Name", dataBaseClassName);
                      connectionInfo.setAttributes (propertyBag);
                      connectionInfo.setUserName (userURL);
                      connectionInfo.setPassword (passURL);
                   // Update the table information
                      rcd.getDatabaseController ().setTableLocation (origTable, newTable);
                    //  tableName=newTable.getName();
                //    rcd.getDatabaseController ().setDataSource (rs, tableName, tableName + "_ResultSet");
                      
                  }
              } 
              
              System.out.println("name new Table "+newTable.getName());
           
              
              ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
              
            //Release report.
              rcd.close();
              
          //Use the Java I/O libraries to write the exported content to the file system.
            byte byteArray[] = new byte[byteArrayInputStream.available()];

            //Create a new file that will contain the exported result.
            File file = new File(EXPORT_FILE);
            FileOutputStream fileOutputStream = new FileOutputStream(file);

            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
            int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

            byteArrayOutputStream.write(byteArray, 0, x);
            byteArrayOutputStream.writeTo(fileOutputStream);

            //Close streams.
            byteArrayInputStream.close();
            byteArrayOutputStream.close();
            fileOutputStream.close();
            
            System.out.println("Successfully exported report to " + EXPORT_FILE);
              
      } catch (SQLException ex) {
          
              System.out.println("sono entrato "+ex.getMessage());
      } catch (ReportSDKException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }      
     

    
    }

}

In entrambi i casi le verifiche connessione da esito positivo. Riesco a stampare a video il numero di tabelle contenute nel report. Quindi riesce a vedere cosa c'è nel .rpt.
Se riesci a darmi una mano a capire dove sbaglio, mi faresti una cortesia

Grazie
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,447
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
la prima cosa che mi viene da chiederti è:
quanto interroghi il db riesci ad avere il dataset dei dati?
 

Scripta14

Nuovo Utente
95
8
Ho fatto altre prove dopo la tua risposta, perchè mi era venuto un dubbio. Ti confermo che se chiamo il db ti risponde con le informazioni richieste dalla SELECT.
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,447
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
ok allora a sto punto credo sia sbagliata l'associazione dataset/report
 

Scripta14

Nuovo Utente
95
8
Era il dubbio che mi era venuto. Qui sorge la mia poca esperienza con questa configurazione.
Ti riporto il metodo che genera eclipse nel progetto di esempio.
In particolare non riesco a capire esattamente le informazioni da indicare in queste variabili

non mi è chiaro a cosa si riferisce il server_type. Non so quali altri parametri potrei indicare
String SERVER_TYPE = "JDBC (JNDI)";
idem per quest'altra.
String JNDI_OPTIONAL_NAME = jndiName;


Codice:
 /**
     * Changes the DataSource for each Table
     * @param clientDoc The reportClientDocument representing the report being used
     * @param username  The DB logon user name
     * @param password  The DB logon password
     * @param connectionURL  The connection URL
     * @param driverName    The driver Name
     * @param jndiName        The JNDI name
     * @throws ReportSDKException
     */
    public static void changeDataSource (ReportClientDocument clientDoc, String username, String password,
                                         String connectionURL, String driverName, String jndiName)
            throws ReportSDKException
    {

        changeDataSource (clientDoc, null, null, username, password, connectionURL, driverName, jndiName);
    }

  /**
     * Changes the DataSource for a specific Table
     * @param clientDoc The reportClientDocument representing the report being used
     * @param subreportName    "" for main report, name of subreport for subreport, null for all reports
     * @param tableName        name of table to change.  null for all tables.
     * @param username  The DB logon user name
     * @param password  The DB logon password
     * @param connectionURL  The connection URL
     * @param driverName    The driver Name
     * @param jndiName        The JNDI name
     * @throws ReportSDKException
     */
    public static void changeDataSource (ReportClientDocument clientDoc, String subreportName, String tableName,
                                         String username, String password, String connectionURL, String driverName,
                                         String jndiName) throws ReportSDKException
    {

        PropertyBag propertyBag = null;
        IConnectionInfo connectionInfo = null;
        ITable origTable = null;
        ITable newTable = null;

        // Declare variables to hold ConnectionInfo values.
        // Below is the list of values required to switch to use a JDBC/JNDI
        // connection
        String TRUSTED_CONNECTION = "false";
        String SERVER_TYPE = "JDBC (JNDI)";
        String USE_JDBC = "true";
        String DATABASE_DLL = "crdb_jdbc.dll";
        String JNDI_OPTIONAL_NAME = jndiName;
        String CONNECTION_URL = connectionURL;
        String DATABASE_CLASS_NAME = driverName;

        // The next few parameters are optional parameters which you may want to
        // uncomment
        // You may wish to adjust the arguments of the method to pass these
        // values in if necessary
        // String TABLE_NAME_QUALIFIER = "new_table_name";
        // String SERVER_NAME = "new_server_name";
        // String CONNECTION_STRING = "new_connection_string";
        // String DATABASE_NAME = "new_database_name";
        // String URI = "new_URI";

        // Declare variables to hold database User Name and Password values
        String DB_USER_NAME = username;
        String DB_PASSWORD = password;

        // Obtain collection of tables from this database controller
        if (subreportName == null || subreportName.equals (""))
        {
            Tables tables = clientDoc.getDatabaseController ().getDatabase ().getTables ();
            for (int i = 0; i < tables.size (); i++)
            {
                origTable = tables.getTable (i);
                if (tableName == null || origTable.getName ().equals (tableName))
                {
                    newTable = (ITable) origTable.clone (true);

                    // We set the Fully qualified name to the Table Alias to keep the
                    // method generic
                    // This workflow may not work in all scenarios and should likely be
                    // customized to work
                    // in the developer's specific situation. The end result of this
                    // statement will be to strip
                    // the existing table of it's db specific identifiers. For example
                    // Xtreme.dbo.Customer becomes just Customer
                    newTable.setQualifiedName (origTable.getAlias ());

                    // Change properties that are different from the original datasource
                    // For example, if the table name has changed you will be required
                    // to change it during this routine
                    // table.setQualifiedName(TABLE_NAME_QUALIFIER);

                    // Change connection information properties
                    connectionInfo = newTable.getConnectionInfo ();

                    // Set new table connection property attributes
                    propertyBag = new PropertyBag ();

                    // Overwrite any existing properties with updated values
                    propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                    propertyBag.put ("Server Type", SERVER_TYPE);
                    propertyBag.put ("Use JDBC", USE_JDBC);
                    propertyBag.put ("Database DLL", DATABASE_DLL);
                    propertyBag.put ("JNDIOptionalName", JNDI_OPTIONAL_NAME);
                    propertyBag.put ("Connection URL", CONNECTION_URL);
                    propertyBag.put ("Database Class Name", DATABASE_CLASS_NAME);
                    // propertyBag.put("Server Name", SERVER_NAME); //Optional property
                    // propertyBag.put("Connection String", CONNECTION_STRING); //Optional property
                    // propertyBag.put("Database Name", DATABASE_NAME); //Optional property
                    // propertyBag.put("URI", URI); //Optional property
                    connectionInfo.setAttributes (propertyBag);

                    // Set database username and password
                    // NOTE: Even if the username and password properties do not change
                    // when switching databases, the
                    // database password is *not* saved in the report and must be set at
                    // runtime if the database is secured.
                    connectionInfo.setUserName (DB_USER_NAME);
                    connectionInfo.setPassword (DB_PASSWORD);

                    // Update the table information
                    clientDoc.getDatabaseController ().setTableLocation (origTable, newTable);
                }
            }
        }
        
        // Next loop through all the subreports and pass in the same
        // information. You may consider
        // creating a separate method which accepts
        if (subreportName == null || !(subreportName.equals ("")))
        {
            IStrings subNames = clientDoc.getSubreportController ().getSubreportNames ();
            for (int subNum = 0; subNum < subNames.size (); subNum++)
            {
                Tables tables = clientDoc.getSubreportController ().getSubreport (subNames.getString (subNum)).getDatabaseController ().getDatabase ().getTables ();
                for (int i = 0; i < tables.size (); i++)
                {
                    origTable = tables.getTable (i);
                    if (tableName == null || origTable.getName ().equals (tableName))
                    {
                        newTable = (ITable) origTable.clone (true);

                        // We set the Fully qualified name to the Table Alias to keep
                        // the method generic
                        // This workflow may not work in all scenarios and should likely
                        // be customized to work
                        // in the developer's specific situation. The end result of this
                        // statement will be to strip
                        // the existing table of it's db specific identifiers. For
                        // example Xtreme.dbo.Customer becomes just Customer
                        newTable.setQualifiedName (origTable.getAlias ());

                        // Change properties that are different from the original
                        // datasource
                        // table.setQualifiedName(TABLE_NAME_QUALIFIER);

                        // Change connection information properties
                        connectionInfo = newTable.getConnectionInfo ();

                        // Set new table connection property attributes
                        propertyBag = new PropertyBag ();

                        // Overwrite any existing properties with updated values
                        propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                        propertyBag.put ("Server Type", SERVER_TYPE);
                        propertyBag.put ("Use JDBC", USE_JDBC);
                        propertyBag.put ("Database DLL", DATABASE_DLL);
                    propertyBag.put ("JNDIOptionalName", JNDI_OPTIONAL_NAME);
                        propertyBag.put ("Connection URL", CONNECTION_URL);
                        propertyBag.put ("Database Class Name", DATABASE_CLASS_NAME);
                        // propertyBag.put("Server Name", SERVER_NAME); //Optional property
                        // propertyBag.put("Connection String", CONNECTION_STRING); //Optionalproperty
                        // propertyBag.put("Database Name", DATABASE_NAME); //Optional property
                        // propertyBag.put("URI", URI); //Optional property
                        connectionInfo.setAttributes (propertyBag);

                        // Set database username and password
                        // NOTE: Even if the username and password properties do not
                        // change when switching databases, the
                        // database password is *not* saved in the report and must be
                        // set at runtime if the database is secured.
                        connectionInfo.setUserName (DB_USER_NAME);
                        connectionInfo.setPassword (DB_PASSWORD);

                        // Update the table information
                        clientDoc.getSubreportController ().getSubreport (subNames.getString (subNum)).getDatabaseController ().setTableLocation (origTable, newTable);
                    }
                }
            }
        }
    }

Questo metodo verrebbe richiamato da quest'altro metodo

Codice:
 /**
     * Determine which report to display, and use this to set the reportClientDocument field.
     * @throws ReportSDKException if there is a problem opening the specified document. 
     */
    private void loadReport () throws ReportSDKException
    {
        if (reportClientDocument == null) 
        {
            // Determine the report to display using a file chooser
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle ("Select a report to display");
            fileChooser.setFileFilter(new FileFilter() {

                @Override
                public boolean accept (File f)
                {
                    if (f != null) {
                        if (f.isDirectory()) {
                            return true;
                        }
                        return f.getName ().endsWith (".rpt");
                    }
                    return false;
                }

                @Override
                public String getDescription ()
                {
                    return "Crystal Reports (*.rpt)";
                }
            });

            int returnVal = fileChooser.showOpenDialog(SampleViewerFrame.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String reportFilePath = fileChooser.getSelectedFile().getAbsolutePath ();
               
               // Create a new client document and use it to open the desired report.
               reportClientDocument = new ReportClientDocument ();
               reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
               reportClientDocument.open (reportFilePath, OpenReportOptions._openAsReadOnly);
           
               CRJavaHelper cr=new CRJavaHelper();
               cr.changeDataSource(reportClientDocument, "USER", "PASSWORD", "jdbc:oracle:thin:@NOMESERVER:PORTA:SID", "oracle.jdbc.OracleDriver", null);
            }
        }
    }
 

Scripta14

Nuovo Utente
95
8
Chiudo il thread riportando le soluzioni per quanto richiesto. Spero possano essere utile ad altri. Ovviamente funziona con un file .rpt privo di parametri o formule. Per queste casiste al prossimo Thread, perchè ci sto studiando su:boh::boh::search::search::D:D......Ma veniamo a noi.
Nel caso di prelievo dei dati da Oracle:
Codice:
public class JavaConnectionOracleSenzaParametri {
     
    private static Connection dbcon = null;
    private static PreparedStatement pstmt = null;
    private static ResultSet rs = null;

    public static void main(String[] args) {
        String connURL = "jdbc:oracle:thin:@NOMESERVER:PORTA:SID";
        String dataBaseClassName="oracle.jdbc.driver.OracleDriver";
        String userURL = "USERNAME";
        String passURL = "PASSWORD";
         PropertyBag propertyBag = null;
         IConnectionInfo connectionInfo = null;
         ITable origTable = null;
         ITable newTable = null;
         String TRUSTED_CONNECTION = "false";
        // String SERVER_TYPE = "JDBC (JNDI)";
         String SERVER_TYPE = "Server Oracle";
         String USE_JDBC = "true";
       //  String DATABASE_DLL = "crdb_jdbc.dll";
         String DATABASE_DLL = "crdb_oracle.dll";
        String theFile="C:\\ProveCR2013\\ReportOracle.rpt";
       
         
         String EXPORT_FILE = "C:\\ProveCR2013\\myExportedReportfromOracle.pdf";
         String tableName=null;
      
         String subreportName=null;
         Tables tables=null;
         Fields pFields = null;
         BasicConfigurator.configure();
        

    try {
                ReportClientDocument rcd=new ReportClientDocument();
                     
                    rcd.open(theFile, OpenReportOptions._openAsReadOnly);
                    
                    
                    rcd.getDatabaseController().logon(userURL,passURL);
                     tables = rcd.getDatabaseController ().getDatabase ().getTables ();
                     
                   
                     for (int i = 0; i < tables.size (); i++)
                        { 
                     
                    
                     connectionInfo =tables.getTable(0).getConnectionInfo();
                            
                      System.out.println("user connessione "+connectionInfo.getUserName());
                      System.out.println("password connessione "+connectionInfo.getPassword());

                      // Set new table connection property attributes
                      propertyBag = new PropertyBag ();
                      propertyBag=connectionInfo.getAttributes();
                      System.out.println(" attributi connessione "+propertyBag.getPropertyIDs());
                    
                      // Overwrite any existing properties with updated values
                        propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                        propertyBag.put ("Server Type", SERVER_TYPE);
                  
                      propertyBag.put ("Use JDBC", USE_JDBC);
                        propertyBag.put ("Database DLL", DATABASE_DLL);
                        propertyBag.put ("Connection URL", connURL);
                        propertyBag.put ("Database Class Name", dataBaseClassName);
                        connectionInfo.setAttributes (propertyBag);
                        connectionInfo.setUserName (userURL);
                        System.out.println("user nuova connessione "+connectionInfo.getUserName());
                        connectionInfo.setPassword (passURL);
                        System.out.println("password nuova connessione "+connectionInfo.getPassword());
                        connectionInfo.setKind(ConnectionInfoKind.SQL);
                        int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB; 
                        // Now replace the connections 
                        rcd.getDatabaseController().replaceConnection(connectionInfo, connectionInfo, null, replaceParams); 
                        }
             
                      
                   // Update the table information
//                  rcd.getDatabaseController ().setTableLocation (origTable, newTable);
                 
                  
                      
                          
                
              
              ByteArrayInputStream byteArrayInputStream = null;
        
                byteArrayInputStream = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
            
              
           //Release report.
              
                rcd.close();
   
            
              
          //Use the Java I/O libraries to write the exported content to the file system.
            byte byteArray[] = new byte[byteArrayInputStream.available()];

            //Create a new file that will contain the exported result.
            File file = new File(EXPORT_FILE);
            FileOutputStream fileOutputStream = null;
        
                fileOutputStream = new FileOutputStream(file);
        

            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
            int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

            byteArrayOutputStream.write(byteArray, 0, x);
        
                byteArrayOutputStream.writeTo(fileOutputStream);
            
            //Close streams.
        
                byteArrayInputStream.close();
        
                byteArrayOutputStream.close();
        
            
            System.out.println("Successfully exported report to " + EXPORT_FILE);
    }  
             catch (ReportSDKException e) {
                    System.out.println(e.getMessage());
                }
            catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
   
 

    
    }

}

Prelievo dati da DB ACCESS

Codice:
public class JavaConnectionAccess {
     
    private static Connection dbcon = null;
    private Statement stmt = null;
    private static ResultSet rs = null;

    public static void main(String[] args) {
        String connURL = "jdbc:ucanaccess://C://NOME_CARTELLA//DBACCESS.mdb";
        String dataBaseClassName="net.ucanaccess.jdbc.UcanaccessDriver";
       //OPZIONALE SE IL DB NON HA USERNAME E PASSWORD 
       String userURL = "USERNAME";
        String passURL = "PASSWORD";
         PropertyBag propertyBag = null;
         IConnectionInfo connectionInfo = null;
         ITable origTable = null;
         ITable newTable = null;
         String TRUSTED_CONNECTION = "false";
         String SERVER_TYPE = "JDBC (JNDI)";
       
         String USE_JDBC = "true";
         String DATABASE_DLL = "crdb_jdbc.dll";
       
         String theFile="C:\\ProveCR2013\\access_no_param.rpt";
         String EXPORT_FILE = "C:\\ProveCR2013\\myExportedReportAccess.pdf";
         String tableName=null;
         String matricola=null;
         String nominativo=null;
         String subreportName=null;
         Tables tables=null;
         Fields pFields = null;
         
         BasicConfigurator.configure();
        
    
             
          //Create the connection using the static getConnection method
              try {
                Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
              dbcon = DriverManager.getConnection (connURL,"admin",null);
              if(dbcon.isValid(10)) 
                  System.out.println("connessione ancora aperta");
              else 
                  System.out.println("connessione chiusa");
                        
           
                  ReportClientDocument rcd=new ReportClientDocument();
                  
                  
                    rcd.open(theFile, OpenReportOptions._openAsReadOnly);
                    
           
                    
                    tables = rcd.getDatabaseController ().getDatabase ().getTables ();
                     
                    
                     System.out.println("numero di tabelle "+tables.size());
                     for (int i = 0; i < tables.size (); i++)
                        { 
                     
                    
                     connectionInfo =tables.getTable(0).getConnectionInfo();
                            
                    System.out.println("user connessione "+connectionInfo.getUserName());
                    System.out.println("password connessione "+connectionInfo.getPassword());

                    // Set new table connection property attributes
                    propertyBag = new PropertyBag ();
                    propertyBag=connectionInfo.getAttributes();
                    System.out.println(" attributi connessione "+propertyBag.getPropertyIDs());
                  
                    // Overwrite any existing properties with updated values
                      propertyBag.put ("Trusted_Connection", TRUSTED_CONNECTION);
                      propertyBag.put ("Server Type", SERVER_TYPE);
                
                      propertyBag.put ("Use JDBC", USE_JDBC);
                      propertyBag.put ("Database DLL", DATABASE_DLL);
                      propertyBag.put ("Connection URL", connURL);
                      propertyBag.put ("Database Class Name", dataBaseClassName);
                      connectionInfo.setAttributes (propertyBag);
                     connectionInfo.setUserName (rcd.getDatabaseController().findConnectionInfoByDBServerName(elencoServer.get(0)).getUserName());
                      System.out.println("user nuova connessione "+connectionInfo.getUserName());
                      connectionInfo.setPassword (rcd.getDatabaseController().findConnectionInfoByDBServerName(elencoServer.get(0)).getPassword());
                      System.out.println("password nuova connessione "+connectionInfo.getPassword());
                      connectionInfo.setKind(ConnectionInfoKind.DBFile);      
                      
                      int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB; 
                      // Now replace the connections 
                      rcd.getDatabaseController().replaceConnection(connectionInfo, connectionInfo, null, replaceParams);                      
                      
                        }
                     
                
          
           
              
              ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)rcd.getPrintOutputController().export(ReportExportFormat.PDF);
              
            //Release report.
              rcd.close();
              
          //Use the Java I/O libraries to write the exported content to the file system.
            byte byteArray[] = new byte[byteArrayInputStream.available()];

            //Create a new file that will contain the exported result.
            File file = new File(EXPORT_FILE);
            FileOutputStream fileOutputStream = new FileOutputStream(file);

            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
            int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());

            byteArrayOutputStream.write(byteArray, 0, x);
            byteArrayOutputStream.writeTo(fileOutputStream);

            //Close streams.
            byteArrayInputStream.close();
            byteArrayOutputStream.close();
            fileOutputStream.close();
            
            System.out.println("Successfully exported report to " + EXPORT_FILE);
              
              }
       catch (ReportSDKException e) {
        System.out.println(" A "+e.getMessage());
        System.out.println(" B "+e.getLocalizedMessage());
        System.out.println(" c "+e.getSDKError().toString());
        System.out.println(" D "+e.errorCode());
        
           
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
              catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
              catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }      
     

    
    }
 

Skills07

Head of Development
Staff Forum
Utente Èlite
35,447
11,502
CPU
Ryzen 7 5800x
Dissipatore
Deepcool gammax l240 v2
Scheda Madre
Aourus Gigabyte X-470 ultra gaming
HDD
Samsung Evo 850 250gb ,2tb x 2 toshiba P300, 256 Ssd silicon power, Samsung evo plus 1tb nvme
RAM
32 gb G.Skill Tridentz 3200 mhz RGB
GPU
Zotac - RTX 3070 Ti Trinity OC
Monitor
ASUS TUF QHD 165hz IPS, ITEK GCF 165hz IPS QHD, Samsung Curvo 144hz QHD
PSU
Seasonic Focus 650w 80 platinum
Case
Coolermaster h500p
Periferiche
Asus Tuf Wireless
Net
Fibra Tim 100mb
OS
Windows 10 Pro 64 bit
ok chiudo, mettendo il tag risolto... buona soluzione
 
Stato
Discussione chiusa ad ulteriori risposte.

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!