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 等
配置文件如下:
[SETUPKIT]
;
;-------------------------------------------------------------------------------
; Setup wrapper master log file and display name
;-------------------------------------------------------------------------------
;
NAME = PIOLEDB
DISPLAYNAME = PI OLEDB 2016
;
;------------------------------------
; Silent/Interactive options
; Should be TRUE for silent installs
;------------------------------------
SUPPRESSCOMPLETIONMESSAGE = FALSE
SUPPRESSPROGRESSMESSAGE = FALSE
SUPPRESSHEADERMESSAGE = FALSE
SUPPRESSDIALOGS = FALSE
;----------------------------
; Other setup wrapper options
;----------------------------
SHOWSKIPPEDMODULES = FALSE
FEATUREUPGRADE = FALSE
[NUMSETUPMODULES]
NUM=12
[SETUPMODULES]
1 = dotnet460Setup
2 = pibufss\PreInstallTasks
; PIBufssPreInstallTasks required by pibufss.msi (4.3) and pibufss_x64.msi (4.3)
;
3 = MSRuntimes\MSRuntimes.msi
; MSRuntimes.msi required by: pisdk.msi (1.4.4) because of its VB6 controls.
;
4 = VS2008Redistrib\MSVC9SP1x64Redistrib
; MSRuntimes VS2008 SP1 (32-bit and 64-bit) required by: AFClient PISDKRegistry merge module, and PIBufss piapi.msm
;
5 = VS2010Redistrib\MSRuntimesSetupVS2010SP1_x64
; MSRuntimes VS2010 SP1 required by: pisdk (1.4.4) because of the following 3.4.390.xx utilities and dll's: pictrdll.dll, pigetmsg.exe, piconfig.exe, pidiag.exe
;
6 = VS2012Redistrib\MSRuntimesVS2012_x64
; MSRuntimes VS2012 SP1 (32-bit and 64-bit) required by: pibufss (4.3)
;
;PI SDK (64-bit)
7 = pisdk\PISDK_x64.msi
;
;
; PI Buffer Subsystem
8 = pibufss\PIBufss_x64.msi
9 = PIOLEDB64.msi
10 = VS2015Redistrib\MSRuntimesVS2015_x64
11 = PI_SQL_Data_Access_Server_OLE_DB_x64.msi
12 = PI_SQL_Commander_Lite_x64.msi
[COMMANDLINE]
2 =
;MSRuntimes
3 = ALLUSERS=1 REBOOT=Suppress /qb-
;2008 SP1 Runtimes (32-bit and 64-bit)
4 = /qb- /norestart
;2010 SP1 Runtimes (32-bit and 64-bit)
5 = /norestart /passive
;2012 SP1 Runtimes (32-bit and 64-bit)
6 = /norestart /passive
;PI SDK (64-bit)
7 = NOPISDKBUFFERING=1 ALLUSERS=1 REBOOT=Suppress /qb-
; PI Buffer Subsystem (64-bit)
8 = ALLUSERS=1 REBOOT=Suppress /qb-
9 = ALLUSERS=1 /qr
10 = /norestart /passive
12 = ALLUSERS=1 /qr
[UPGRADECOMMANDLINE]
;PI SDK (32-bit, 64-bit)
7 = REINSTALL=ALL REINSTALLMODE=vemus
[DISPLAYNAME]
1 = DotNet 4.6
4 = Microsoft Visual C++ 2008 x64 Redistributable
[CHECKFORINSTALLEDONLY]
[UNSUPPORTED_OPERATING_SYSTEMS_MESSAGE]
; Messages for X86 or X64 take priority over operating system specific messages.
;
;X86 = Setup initialization has failed. This setup kit cannot be installed on 32-bit Operating Systems. Setup cannot continue.
WinXP = Windows XP is not supported.
Vista = Service Pack 2 is required on Windows Vista.
Win7 = Service Pack 1 is required on Windows 7.
Win2K = Windows 2000 is not supported.
WinNET = = Windows Server 2003 is not supported.
Win2008 = Service Pack 2 is required on Windows Server 2008.
Win2008R2 = Service Pack 1 is required on Windows Server 2008 R2.
[UNSUPPORTED_OPERATING_SYSTEMS]
;
;-------------------------------------------------------------------------------
; Defined Operating Systems
;
; (Win95, Win98, WinME, WinNT, Win2K, WinXP, WinNET, Vista, Win2008, Win7,
; Win2008R2, Win8, Win2012, Win81, Win2012R2)
;
; If Defined Operating Systems used, all versions of specified operating system
; is defined.
;
; Defined Operating Systems with Service Packs or sub category
;
; (WinNTPreSp6a, WinNTSp6a, Win2KNoSp, Win2KSp1, Win2KSp2, Win2KSp3, Win2KSp4,
; WinXPNoSp, WinXPSp1, WinXPSp2, WinNETNoSp , WinNETSp1, WinNETSp2, VistaNoSp,
; VistaSp1, VistaSp2, Win2008NoSP, Win2008Sp1, Win2008Sp2, CORE, Win7,
; Win2008R2, Win8, Win2012, Win81, Win2012R2, X64)
;
; If Defined Operating Systems with Service Packs used, only that specific
; service pack within operating system is defined. The exception is for
; WinNT where only Sp6a or pre Sp6a is defined.
;
; A 0 entry denotes that the setup can not run on the given operating systems.
; An entry that corresponds to an entry in the [SETUPMODULES] section denotes
; that the particular setup module will be skipped on the given operating system
;-------------------------------------------------------------------------------
;
0 = Win95, Win98, WinME, WinNT, Win2K, WinXP, WinNET, VistaNoSp, VistaSp1, Win2008NoSp, Win2008Sp1, Win7NoSp, Win2008R2NoSp, CORE
;
; VS2008Redistrib\MSVC9SP1x64Redistrib
4= X86
;
; VS2010Redistrib\MSRuntimesSetupVS2010SP1_x64
5 = X86
;
; VS2012Redistrib\MSRuntimesVS2012_x64
6 = X86
;
; PI SDK (64-bit)
7 = X86
;
;
; PI Buffer Subsystem (64-bit)
8 = X86
;
; PI OLEDB (64-bit)
9 = X86
;MSI's or Setup wrapper Dll's can write to this section to dynamically change
;the command line for an MSI at setup runtime.
[RUNTIME_PARAMETERS]
;This section is used by the pibufss pre-install tasks and post-install tasks.
[PIBUFSS]