WEB开发网
开发学院数据库DB2 构建DB2 Cube View元数据桥之二 阅读

构建DB2 Cube View元数据桥之二

 2005-11-27 21:58:54 来源:WEB开发网   
核心提示: ·ImaginationCubed:网络涂鸦齐开心·构建DB2 Cube View元数据桥(1)·构建DB2 Cube View元数据桥之一·构建DB2 Cube View元数据桥之三·cube子句的用法·TDecisionCube使
    ·ImaginationCubed:网络涂鸦齐开心
    ·构建DB2 Cube View元数据桥(1)
    ·构建DB2 Cube View元数据桥之一
    ·构建DB2 Cube View元数据桥之三
    ·cube子句的用法
    ·TDecisionCube
使用应用程序接口

  用于调用md_message()存储过程的例程C++代码在sqllib/samples/olap/client/db2mdapiclient.cpp的DB2 Cube View产品中。

  如果你是使用Java编写程序,那么这里给出使用JDBC调用存储过程的样例代码段:

/* Calls the DB2 stored procedure passing in the request string
* as the first parameter and the metadata string as the second
* parameter. If xml(标准化越来越近了)RequestString contains a script or no output
* metadata is required the xml(标准化越来越近了)Metadata parameter may be null.
* The outputMetadata boolean controls what is returned by the
* method. If it is true any output metadata is returned. If
* false the response output is returned. */
private String callDB2StoredProc(String xml(标准化越来越近了)RequestString,
String xml(标准化越来越近了)MetadataString,
boolean outputMetadata)
throws OCException,
OCApiException
{
/* Create an SQL command to call the Stored procedure in DB2
* to get the xml(标准化越来越近了) */
String sql = "CALL db2info.MD_MESSAGE (?, ?, ?)";
String response = null;
String xml(标准化越来越近了)MetadataResponse = null;
CallableStatement callStmt = null;

try
{
callStmt = auroraCatalogConnection.prepareCall(sql);

/* Set input parameter to request and metadata strings. */
callStmt.setString (1, xml(标准化越来越近了)RequestString);
callStmt.setString (2, xml(标准化越来越近了)MetadataString);

/* Register the output parameters. */
callStmt.registerOutParameter (2, Types.VARCHAR);
callStmt.registerOutParameter (3, Types.VARCHAR);

/* Call the stored procedure */
callStmt.execute();

/* Retrieve output parameters. If the procedure was called with
* a request that returns metadata in the middle parameter then
* xml(标准化越来越近了)MetadataResponse will store the output xml(标准化越来越近了). */
if (outputMetadata == true)
xml(标准化越来越近了)MetadataResponse = callStmt.getString(2);
response = callStmt.getString(3);

/* See if there are any warnings. */
SQLWarning warning = callStmt.getWarnings();

/* If execute returns a warning with a non-zero SQL state
* then the API has had an error and returned some response
* info in the output xml(标准化越来越近了) document. */
if (warning != null)
{
OCLog.trace("Stored procedure execute returned a warning.");
OCLog.trace("SQL state: " + warning.getSQLState());
OCLog.trace("SQL state: " + warning.getErrorCode());

/* readResponseFromxml(标准化越来越近了) will throw an OCApiException containing
* the error info (which will then be thrown to our caller) or
* it will throw an OCException if a parsing error occurred. If
* for some strange reason the file does not contain error
* info it will just return and then we'll throw an OCException
* to notify the user. */
try { readResponseFromxml(标准化越来越近了)(response); }

/* If an API exception was thrown add the SQL state etc to
* it and then throw it again. */
catch (OCApiException apie)
{
apie.setSqlException(warning);

throw apie;
}
/* If we have had a warning we always want to rollback any changes.
* If we have a problem rolling back the exception will be caught
* below. */
finally
{
auroraCatalogConnection.rollback();
}

/* If we got here there must have been a warning with nothing
* in the output xml(标准化越来越近了) so throw an exception explaining this. */
throw new OCException("OC_ERR_API_DB2_STORED_PROC_FAIL_NO_INFO");
}
}
/* If we had an error executing the SQL, log the information and
* throw an exception. We also rollback any changes and catch
* the exception if the rollback has a problem. */
catch (SQLException e)
{
OCApiException newe = new OCApiException(e);
OCLog.trace( newe.getMessage() );
logExceptionInfo(e);

try { auroraCatalogConnection.rollback(); }
catch (SQLException e2)
{
OCLog.trace("An exception also occurred rolling back.");
logExceptionInfo(e2);
}

throw newe;
}

Tags:构建 DB Cube

编辑录入:coldstar [复制链接] [打 印]
赞助商链接