Java 访问PI 数据库
需求
- 使用java 去访问PI 数据库
前提环境
- 已经在远程安装了PI 数据库。
- windows 系列
- jre 8 及以上
资料收集
- PI官网https://techsupport.osisoft.com/
- 在官网上,开发者技术 上,可以看到相关帮助文档与软件下载
- 由官网(Developer Technologies)介绍可知:常用的访问PI数据库的方案有
- 使用 JDBC Driver 或 ODBC Driver
- 使用 PI Web Api
- 使用 sdk
确定方案
根据需求,决定选择 JDBC Driver 来实现java 访问PI数据库
原理
PI的JDBC驱动程序是一个java数据库连接驱动,通过SQL查询提供了强大的数据访问PI系统 。PI JDBC Driver 提供了一个类似于java 访问Mysql或者Oracle 同样的方式。
但是,JDBC Driver 是 通过中间层 PI SQL DATA Access Server 来实现 PI JDBC driver 和 PI OLEDB Enterprise/PI OLEDB providers 之间的交互的。
PI SQL DAS(OLE DB)在客户端 通过 Net.TCP 或者 HTTPS 来提供安全的网络连接
软件安装
一定要注意安装顺序:
按照摸索的过程书写的文档。其真实安装步骤应该是:
* OLE DB
* PI SQL Data Access Server
* PI JDBC Driver 2016
安装PI JDBC Driver 2016
- PI JDBC Driver 2016 在 windows 上基本要求
- windows7 及以上
- JRE 7 及以上
- 已经安装了 PI SQL DATA Access Server
- 安装步骤
- 下载PI JDBC Driver 2016 SP1 Install Kit (Windows)
- 根据安装向导运行,运行 PI-JDBC_2016-SP1_.exe,全部默认
- 安装以后,其安装目录(PIHOME),32bit:C:\Program Files (x86)\PIPC\JDBC,64 bit :C:\Program Files\PIPC\JDBC
- 系统环境变量会自动添加或更新
- PI_RDSA_LIB=PIHOME\JDBC\RDSAWrapper.dll
- PI_RDSA_LIB64=PIHOME\JDBC\RDSAWrapper64.dll
- CLASSPATH=PIHOME\JDBC\PIJDBCDriver.jar
- 打开 cmd,运行
set pi
和set classpath
即可查询环境变量是否设置
- 安装完成
- 注意事项
- 如果没有安装 PI SQL DATA Access Server,安装了 JDBC Driver 也没有什么用。你会发现 JDBC 的安装目录下提供了一个类似于 JDBC访问Mysql的包而已。
- 甚至,你自身的系统为64bit,它却会静默安装 将32 bit 的安装上去。
- 程序还提供了一种静默安装方案
- msiexec.exe /i PIJDBC.msi REBOOT=Suppress ALLUSES=1 /qn
- msiexec.exe /i PIJDBC64.msi REBOOT=Suppress ALLUSES=1 /qn
(未实践)
安装PI SQL DATA Access Serve(OLE DB)
- PI SQL DAS 在 windows 上基本要求
- 需要安装 Microsoft .Net Framework 4.6
- 需要安装 PI OLEDB Provider 或者 PI OLEDB Enterprise
- 安装步骤
- 下载PI SQL Data Access Server (OLE DB) Install Kit
- 使用拥有管理员权限的账户来安装
- 根据安装向导运行,运行 PISQLDAS_*.exe, 点击Ok
- 当你运行安装时,PI SQL DAS 会根据你的操作系统版本自动选择安装 32bit 或者 64bit
- HTTPS port 默认为 5461,Net.TCP 为 5462
- 自动安装对应的证书
- 会修改对应端口的防火墙
- 安装完成
- 校验服务是否在运行。我的电脑->管理->服务 中查看 是否新增了一个 PI SQL Access Server(OLE DB)的服务在运行状态
安装 PI OLEDB Provider 或者 PI OLEDB Enterprise
- PI JDBC Driver 2016 在 windows 上基本要求
- windows7 及以上
- JRE 7 及以上
- 需要安装 Microsoft .Net Framework 4.6 (企业版中包含此安装包)
- 安装步骤
- 下载PI OLEDB Provider 或者PI OLEDB Enterprise
- 根据安装向导运行,运行 PI-OLEDB_*.exe,全部默认
- 安装完成
- 注意
- PI OLEDB Enterprise 比 PI OLEDB Provider 要全面较多。所安装的软件也会更多。
- msiexec.exe /i PIOLEDBEnterprise64.msi REBOOT=Suppress ALLUSES=1 /qn
安装 PI ODBC Driver
- 在 windows 上基本要求
- windows7 及以上
- JRE 7 及以上
- 安装步骤
- 下载 PI ODBC Driver
- 根据安装向导运行,运行 PI-ODBC_*.exe,全部默认
- 安装完成
- 它包含一个工具SQL Commander Lite,可以用来查询SQL
通过上述的安装步骤之后,从开始菜单打开SQL Commander Lite,可以连接上 PI 服务,并且使用 类似 sql 语句去查询PI 中的数据。具体 sql语句 查看 帮助文档如PI-OLEDB-Enterprise-2016-R2-User-Guide.pdf
精简安装包
经过上述的安装步骤之后,会发现,其安装很是臃肿,比如,原本我是 64bit的操作系统,我只想要安装 64bit 即可,上述的安装步骤,却会将 32bit 也全部安装。
对比各个包解压后的文件,查看其 setup.ini, 则会发现 setup.ini 是一些关于安装文件与安装顺序的配置。调整 setup.ini 中的相关安装文件顺序与安装命令,一一对应,将其中对应的 32 bit 配置删除,并且将多个安装包 合并在一起。
执行 setup.exe 即可集成安装 .Net 4.6/PI OLEDB Provider/PI SQL DAS(OLE DB)/SQL Commander Lite 等
配置文件如下: