Connecting Crystal Reports in NetBeans

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rathnaravi
    New Member
    • Feb 2008
    • 1

    Connecting Crystal Reports in NetBeans

    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.crystaldeci sions.sdk.occa. report.lib.Repo rtSDKException: Unexpected error determining relative path---- Error code:-2147217395 Error code name:serverProg rammingError
    Could anyone help me to solve this problem.
    My Codings
    Code:
    import com.crystaldecisions.reports.sdk.*;
    import com.crystaldecisions.sdk.occa.report.lib.*;
    
    //Java Imports.
    import javax.swing.*;
    
    import java.sql.*;
    
    public class JRCResultsetDatasource {
    
    	private static final String REPORT_NAME = "C:\\Rathna_project\\financial_accounting\\JavaApplication20\\docrep.rpt";
    	
    	public static void launchApplication() {
    		
    		try {
    									
    			//Open report.
    			ReportClientDocument reportClientDoc = new ReportClientDocument();
    			reportClientDoc.open(REPORT_NAME, 0);
                            		
    			//Create SQL query.     
    			String query = "SELECT S_C_DOC_TYPE,S_C_DOC_NO FROM inventory.document_master";
    	
    			//Query database and obtain the Resultset that will be pushed into the report.   
    			ResultSet resultSet = getResultSetFromQuery(query, ResultSet.TYPE_SCROLL_INSENSITIVE); 
    			
    			//Look up existing table in the report to set the datasource for and obtain its alias.  This table must 
    			//have the same schema as the Resultset that is being pushed in at runtime.  The table could be created 
    			//from a Field Definition File, a Command Object, or regular database table.  As long the Resultset
    			//schema has the same field names and types, then the Resultset can be used as the datasource for the table.  
    			String tableAlias = reportClientDoc.getDatabaseController().getDatabase().getTables().getTable(0).getAlias();
    			
    			//Push the Java ResultSet into the report.  This will then be the datasource of the report.
    			reportClientDoc.getDatabaseController().setDataSource(resultSet, tableAlias , "resultsetTable");
    			
    			//Launch JFrame that contains the report viewer.
    			new ReportViewerFrame(reportClientDoc);		
    			
    		}
    		catch(ReportSDKException ex) {	
    			System.out.println(ex);
    		}
    		catch(Exception ex) {
    			System.out.println(ex);			
    		}
    		
    	}
    	
    	/**
    	 * Simple utility function for obtaining result sets that will be pushed into the report.  
    	 * This is just standard querying of a Java result set and does NOT involve any 
    	 * Crystal JRC SDK functions.  
    	 */
    	private static ResultSet getResultSetFromQuery(String query, int scrollType) throws SQLException, ClassNotFoundException {
            try {
    
                //Load JDBC driver for the database that will be queried.  
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (InstantiationException ex) {
                ex.printStackTrace();
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
    		
    		//Construct JDBC connection.
    		//final String DBUSERNAME = "root";
    		//final String DBPASSWORD = "";
    		final String CONNECTION_URL = "jdbc:mysql://localhost:3306/inventory?user=root";
    		
    		java.sql.Connection connection = DriverManager.getConnection(CONNECTION_URL); 
    		Statement statement = connection.createStatement(scrollType, ResultSet.CONCUR_READ_ONLY);
    		
    		//Execute query and return result sets.
    		return statement.executeQuery(query);
    
    	}
    	
    	public static void main(String [] args) {
    		
    		//Event-dispatching thread to run Swing GUI.  This is good practice for Swing applications
    		//to help ensure that events are dispatched in a predicatable order. 
    		//For more information on using this method, refer to the SUN site below for more details:
    		//http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
    		SwingUtilities.invokeLater(new Runnable() { 
    			public void run() {
    				//Hand-off to worker function to start application.
    				launchApplication();				
    			}
    		});
    					
    	}
    	
    }
    Last edited by Nepomuk; Jul 1 '09, 02:06 PM. Reason: Added [code] tags
  • KGanesh
    New Member
    • Jul 2009
    • 1

    #2
    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

    Comment

    • kuman vadadoriy
      New Member
      • Apr 2013
      • 1

      #3
      crystal report

      hello sir,

      i send you some code and you run this ...
      i think it is usefull for you....

      mport java.io.*;
      import java.util.*;
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event. *;
      import java.sql.*;
      class Form extends JFrame{

      JButton add;
      JPanel panel,pan;
      JLabel label1,label2,l abel3,label4,la bel5;
      final JTextField text1,text2,tex t3,text4,text5;
      Form() {
      label1 = new JLabel();
      label1.setText( "Employee Id:");
      text1 = new JTextField(20);

      label2 = new JLabel();
      label2.setText( "Employee Name:");
      text2 = new JTextField(20);

      label3 = new JLabel();
      label3.setText( "Employee Designation:");
      text3 = new JTextField(20);

      label4 = new JLabel();
      label4.setText( "Employee Salary:");
      text4 = new JTextField(20);

      label5 = new JLabel();
      label5.setText( "Employee Address:");
      text5 = new JTextField(20);

      ADD=new JButton("Print" );

      panel=new JPanel(new GridLayout(6,2) );
      panel.add(label 1);
      panel.add(text1 );
      panel.add(label 2);
      panel.add(text2 );
      panel.add(label 3);
      panel.add(text3 );
      panel.add(label 4);
      panel.add(text4 );
      panel.add(label 5);
      panel.add(text5 );
      panel.add(ADD);
      add(panel,Borde rLayout.CENTER) ;
      setTitle("FORM" );

      ADD.addActionLi stener(new ActionListener( ) {
      public void actionPerformed (ActionEvent ae){
      String id[]={text1.getText ()};
      String name[]={text2.getText ()};
      String des[]={text3.getText ()};
      String sal[]={text4.getText ()};
      String add[]={text5.getText ()};

      java.util.List< String> list = new ArrayList<Strin g>();
      for(int i = 0; i < id.length; i++) {
      String line = id[i]+" "+name[i]+" "+des[i]+" "+sal[i]+" "+add[i];
      list.add(line);
      }
      writeToFile(lis t, "Employee.txt") ;
      JOptionPane.sho wMessageDialog( null,"Inserted into File");
      text1.setText(" ");
      text2.setText(" ");
      text3.setText(" ");
      text4.setText(" ");
      text5.setText(" ");

      }
      });
      }
      private static void writeToFile(jav a.util.List<Str ing> list, String path) {
      BufferedWriter out = null;
      try {
      File file = new File(path);
      out = new BufferedWriter( new FileWriter(file ,true));
      for (String s : list) {
      out.write(s);
      out.newLine();
      }
      out.close();
      } catch(IOExcepti on e) {}
      }
      }
      class InsertToFile{
      public static void main(String arg[]) {
      try
      {
      Form frame=new Form();
      frame.setSize(3 00,300);
      frame.setVisibl e(true);
      }
      catch(Exception e)
      {}
      }
      }

      Comment

      Working...