思迈特Java笔试题_Java示例. - Smartbi V9 帮助中心 - Smartbi 在线知识中心

import java.util.List;

import smartbi.net.sf.json.*;

import smartbi.sdk.ClientConnector;

import smartbi.sdk.InvokeResult;

import smartbi.sdk.RemoteException;

public class JavaJsonAPITest {

//打印字段信息

private static void printFieldNames(JSONArray fNames) {

List names = (List) JSONArray.toList(fNames);

for (String fieldName : names)

System.out.print(fieldName + ", ");

}

//打印结果集信息

private static void printMatrix(JSONArray data) {

List> rows = JSONArray.toList(data);

for (List row : rows) {

System.out.println();

for (String cell : row) {

System.out.print(cell + ", ");

}

}

}

public static void main(String[] args) {

String Smartbi_URL = "http://localhost:8080/smartbi";

ClientConnector conn = new ClientConnector(Smartbi_URL);

try {

//第一次调用必须建立一个连接,后续调用则不必再建连接

boolean loginSuceeded = conn.open("admin", "manager");

if (loginSuceeded) {

// 业务查询ID(对应示例库中的"根目录\功能演示\查询定义\原生SQL查询\带参数的原生SQL")

String bizViewId = "I2c94907127855da201278df551b62602";

// 参数ID

String paramId = "OutputParameter.I2c94907127855da201278df551b62602.产品名称参数_列表对话框";

// 参数真实值

String paramValue = "牛奶,花生,饼干,猪肉,汽水";

JSONObject param = new JSONObject();

param.put("id", paramId);

param.put("value", paramValue);

JSONArray params = new JSONArray();

params.put(param);

String paramsJsonArrStr = params.toString();

//每页行数

int rowsPerPage = 2;

// 是否获取总行数

boolean getTotalRows = true;

InvokeResult result = conn.remoteInvoke("BusinessViewService","openLoadDataView",

new Object[] { bizViewId,paramsJsonArrStr, rowsPerPage, getTotalRows });

if (result.isSucceed()) {

JSONObject ret = (JSONObject) result.getResult();

String loadDataClientId = ret.getString("clientId");

int totalRows = ret.getInt("totalRowCount");

printFieldNames(ret.getJSONArray("fieldNames"));

int pages = totalRows / rowsPerPage + (totalRows % rowsPerPage == 0 ? 0 : 1);

for (int pageNum = 0; pageNum < pages; pageNum++) {

InvokeResult viewData = conn.remoteInvoke("BusinessViewService",

"loadViewData",

new Object[] { loadDataClientId, pageNum });

JSONArray pageData = (JSONArray) viewData.getResult();

printMatrix(pageData);

}

conn.remoteInvoke("BusinessViewService", "closeLoadDataView", new Object[] { loadDataClientId });

}

}

} catch (RemoteException e) {

e.printStackTrace();

} finally {

// 关闭应用连接器

conn.close();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值