Connecting Tech Pros Worldwide Help | Site Map

Connecting Crystal Reports in NetBeans

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 9 '08
I am using NetBeans 5.0.I tried to connect MySQL with Crystal Reports XI.When writing the coding in Java Application.I get the following error.
com.crystaldecisions.sdk.occa.report.lib.ReportSDK Exception: Unexpected error determining relative path---- Error code:-2147217395 Error code name:serverProgrammingError
Could anyone help me to solve this problem.
My Codings
Expand|Select|Wrap|Line Numbers
  1. import com.crystaldecisions.reports.sdk.*;
  2. import com.crystaldecisions.sdk.occa.report.lib.*;
  3.  
  4. //Java Imports.
  5. import javax.swing.*;
  6.  
  7. import java.sql.*;
  8.  
  9. public class JRCResultsetDatasource {
  10.  
  11.     private static final String REPORT_NAME = "C:\\Rathna_project\\financial_accounting\\JavaApplication20\\docrep.rpt";
  12.  
  13.     public static void launchApplication() {
  14.  
  15.         try {
  16.  
  17.             //Open report.
  18.             ReportClientDocument reportClientDoc = new ReportClientDocument();
  19.             reportClientDoc.open(REPORT_NAME, 0);
  20.  
  21.             //Create SQL query.     
  22.             String query = "SELECT S_C_DOC_TYPE,S_C_DOC_NO FROM inventory.document_master";
  23.  
  24.             //Query database and obtain the Resultset that will be pushed into the report.   
  25.             ResultSet resultSet = getResultSetFromQuery(query, ResultSet.TYPE_SCROLL_INSENSITIVE); 
  26.  
  27.             //Look up existing table in the report to set the datasource for and obtain its alias.  This table must 
  28.             //have the same schema as the Resultset that is being pushed in at runtime.  The table could be created 
  29.             //from a Field Definition File, a Command Object, or regular database table.  As long the Resultset
  30.             //schema has the same field names and types, then the Resultset can be used as the datasource for the table.  
  31.             String tableAlias = reportClientDoc.getDatabaseController().getDatabase().getTables().getTable(0).getAlias();
  32.  
  33.             //Push the Java ResultSet into the report.  This will then be the datasource of the report.
  34.             reportClientDoc.getDatabaseController().setDataSource(resultSet, tableAlias , "resultsetTable");
  35.  
  36.             //Launch JFrame that contains the report viewer.
  37.             new ReportViewerFrame(reportClientDoc);        
  38.  
  39.         }
  40.         catch(ReportSDKException ex) {    
  41.             System.out.println(ex);
  42.         }
  43.         catch(Exception ex) {
  44.             System.out.println(ex);            
  45.         }
  46.  
  47.     }
  48.  
  49.     /**
  50.      * Simple utility function for obtaining result sets that will be pushed into the report.  
  51.      * This is just standard querying of a Java result set and does NOT involve any 
  52.      * Crystal JRC SDK functions.  
  53.      */
  54.     private static ResultSet getResultSetFromQuery(String query, int scrollType) throws SQLException, ClassNotFoundException {
  55.         try {
  56.  
  57.             //Load JDBC driver for the database that will be queried.  
  58.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  59.         } catch (InstantiationException ex) {
  60.             ex.printStackTrace();
  61.         } catch (IllegalAccessException ex) {
  62.             ex.printStackTrace();
  63.         } catch (ClassNotFoundException ex) {
  64.             ex.printStackTrace();
  65.         }
  66.  
  67.         //Construct JDBC connection.
  68.         //final String DBUSERNAME = "root";
  69.         //final String DBPASSWORD = "";
  70.         final String CONNECTION_URL = "jdbc:mysql://localhost:3306/inventory?user=root";
  71.  
  72.         java.sql.Connection connection = DriverManager.getConnection(CONNECTION_URL); 
  73.         Statement statement = connection.createStatement(scrollType, ResultSet.CONCUR_READ_ONLY);
  74.  
  75.         //Execute query and return result sets.
  76.         return statement.executeQuery(query);
  77.  
  78.     }
  79.  
  80.     public static void main(String [] args) {
  81.  
  82.         //Event-dispatching thread to run Swing GUI.  This is good practice for Swing applications
  83.         //to help ensure that events are dispatched in a predicatable order. 
  84.         //For more information on using this method, refer to the SUN site below for more details:
  85.         //http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
  86.         SwingUtilities.invokeLater(new Runnable() { 
  87.             public void run() {
  88.                 //Hand-off to worker function to start application.
  89.                 launchApplication();                
  90.             }
  91.         });
  92.  
  93.     }
  94.  
  95. }
Newbie
 
Join Date: Jul 2009
Posts: 1
#2: Jul 1 '09

re: Connecting Crystal Reports in NetBeans


Hello,

I am alaso facing the same problem and i am using it in a web application. Please let me know if you have found the solution.

Thank you
Ganesh
Reply