#鸿蒙通关秘籍#如何在鸿蒙系统间查询远程设备上的数据库?

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
HTTPS碧海蓝天

在鸿蒙设备间查询远程设备上的数据,需要完成以下步骤:

  1. 获取可用的设备ID: bash import { distributedDeviceManager } from '@kit.DistributedServiceKit'; import { BusinessError } from '@kit.BasicServicesKit';

    let dmInstance; let deviceId = undefined;

    try { dmInstance = distributedDeviceManager.createDeviceManager("com.example.appdatamgrverify"); let devices = dmInstance.getAvailableDeviceListSync();

    deviceId = devices[0].networkId; } catch (err) { console.error("createDeviceManager errCode:" + err.code + ",errMessage:" + err.message); }

  2. 使用设备ID进行远程查询: bash let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); if(store != undefined && deviceId != undefined) { store.remoteQuery(deviceId, 'EMPLOYEE', predicates, ['ID', 'NAME', 'AGE', 'SALARY', 'CODES'], (err, resultSet) => { if (err) { console.error(Failed to remoteQuery data. Code:${err.code},message:${err.message}); return; } console.info(ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}); }) }

分享
微博
QQ
微信
回复
3天前
相关问题