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
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();
}
});
}
}
Comment