Java?使用JDBC操作PI數(shù)據(jù)庫(kù)的方法
一、概述
(1)環(huán)境:windows 系列、jre 8 及以上
(2)資料:PI 官網(wǎng) https://techsupport.osisoft.com/
(3)常用的訪問(wèn)PI數(shù)據(jù)庫(kù)的方案有:①使用 JDBC Driver 或 ODBC Driver;②使用 PI Web Api;③使用 sdk
本次,我們選擇使用 JDBC Driver 來(lái)實(shí)現(xiàn)java 訪問(wèn)PI數(shù)據(jù)庫(kù)。
二、JDBC訪問(wèn)PI數(shù)據(jù)庫(kù)原理
PI的JDBC驅(qū)動(dòng)程序是一個(gè)java數(shù)據(jù)庫(kù)連接驅(qū)動(dòng),通過(guò)SQL查詢提供了強(qiáng)大的數(shù)據(jù)訪問(wèn)PI系統(tǒng) 。PI JDBC Driver 提供了一個(gè)類似于java 訪問(wèn)Mysql或者Oracle 同樣的方式。
但是,JDBC Driver 是 通過(guò)中間層 PI SQL DATA Access Server 來(lái)實(shí)現(xiàn) PI JDBC driver 和 PI OLEDB Enterprise/PI OLEDB providers 之間的交互的。
PI SQL DAS(OLE DB)在客戶端 通過(guò) Net.TCP 或者 HTTPS 來(lái)提供安全的網(wǎng)絡(luò)連接

三、軟件安裝
(1)百度網(wǎng)盤(pán)下載地址:
鏈接: https://pan.baidu.com/s/1SPLpKrfHBPGPzDgb9S_MOQ?pwd=hx7p
提取碼: hx7p
(2)安裝順序應(yīng)該是:
- OLE DB
- PI SQL Data Access Server
- PI JDBC Driver 2016
1.安裝 PI OLEDB
進(jìn)入PI OLEDB目錄,運(yùn)行:PI OLEDB_2016_.exe

在Default Server填寫(xiě)PI服務(wù)器的ip地址:

2.安裝PI SQL Data Access Server (OLE DB)
進(jìn)入目錄,運(yùn)行:PISQLDAS_2016 (1.5.16090.1)_.exe

3.安裝PI JDBC Driver
進(jìn)入PI JDBC (Windows)目錄,運(yùn)行:PI JDBC_2016_.exe

5.安裝PI的SQL查詢工具
為了方便使用還可以一個(gè)PI ODBC程序,該程序包含一個(gè)工具SQL Commander Lite,可以用來(lái)查詢SQL。

通過(guò)上述的安裝步驟之后,從開(kāi)始菜單打開(kāi)SQL Commander Lite,可以連接上 PI 服務(wù),并且使用 類似 sql 語(yǔ)句去查詢PI 中的數(shù)據(jù)。具體 sql語(yǔ)句 查看 幫助文檔如PI-OLEDB-Enterprise-2016-R2-User-Guide.pdf

四、使用JDBC操作PI數(shù)據(jù)庫(kù)
1.SpringBoot集成PIJDBC驅(qū)動(dòng)
從 PI JDBC Driver 安裝后的目錄下取出 PIHOME\JDBC\PIJDBCDriver.jar。將其放在項(xiàng)目的lib 下,引入項(xiàng)目中。


<!-- 引入本地jar包 -->
<dependency>
<groupId>com.osisoft</groupId>
<artifactId>PIJDBCDriver</artifactId>
<version>1.5.16096</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/PIJDBCDriver.jar</systemPath>
</dependency>2.常用JDBC訪問(wèn)數(shù)據(jù)庫(kù)的方式即可查詢PI數(shù)據(jù)庫(kù)
package com.bkc.test;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class GetBAMetaData
{
public static void main(String[] args)
{
// arguments: java GetBAMetaData dasName [trustedConnection protocolOrder logLevel]
// example: java GetBAMetaData myDas yes nettcp:5462 2
String dasName = "localhost";
String dataSourceName = "192.168.1.32";
String isTrustedConnection = "Yes";
String protocolOrder = "Https/Soap:5461,NetTcp:5462";
String logLevel = "0";
System.out.println("\nArguments:");
System.out.println("\tData Access Server Name: " + dasName);
System.out.println("\tUse trusted connection?: " + isTrustedConnection);
System.out.println("\tProtocol order: " + protocolOrder);
System.out.println("\tLog level: " + logLevel);
Connection connection = null;
String url = "";
String driverClassName = "com.osisoft.jdbc.Driver";
ResultSet resultSet = null;
Properties properties = new Properties();
//url = "jdbc:piintegrator://" + dasName;
//url = "jdbc:pioledb://" + dasName + "/Data Source=" + dataSourceName + "; Integrated Security=SSPI";
url = "jdbc:pioledb://" + dasName + "/Data Source=" + dataSourceName + "; Integrated Security=SSPI";
System.out.println(url);
properties.put("TrustedConnection", isTrustedConnection);
properties.put("ProtocolOrder", protocolOrder);
properties.put("LogConsole", "True");
properties.put("LogLevel", logLevel);
try
{
Class.forName(driverClassName).newInstance();
connection = DriverManager.getConnection(url, properties);
DatabaseMetaData metaData = connection.getMetaData();
System.out.println(metaData.getDriverName() + " " + metaData.getDriverVersion());
System.out.println(metaData.getDatabaseProductName());
System.out.println(metaData.getDatabaseProductVersion() + "\n");
// get all tables and views
String tTypes[] = new String[] {"TABLE", "VIEW"};
resultSet = metaData.getTables(null, null, "%", tTypes);
if(!resultSet.first())
throw new Exception ("No rows in the result set.");
// we are just interested in those 4 columns
System.out.print("Catalog || ");
System.out.print("Schema || ");
System.out.print("Table || ");
System.out.println("Table Type\n");
// read the data
while (!resultSet.isAfterLast()) {
System.out.print(resultSet.getString("TABLE_CAT") + " || ");
System.out.print(resultSet.getString("TABLE_SCHEM") + " || ");
System.out.print(resultSet.getString("TABLE_NAME") + " || ");
System.out.println(resultSet.getString("TABLE_TYPE"));
resultSet.next();
}
}
catch (Exception ex)
{
System.err.println(ex);
}
finally
{
try {
if(resultSet != null) resultSet.close();
if(connection != null) connection.close();
} catch (SQLException ex) {
System.err.println(ex);
}
}
}
}到此這篇關(guān)于Java 使用JDBC操作PI數(shù)據(jù)庫(kù)的文章就介紹到這了,更多相關(guān)java jdbc操作pi內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java實(shí)戰(zhàn)之酒店人事管理系統(tǒng)的實(shí)現(xiàn)
這篇文章主要介紹了如何用Java實(shí)現(xiàn)酒店人事管理系統(tǒng),文中采用的技術(shù)有:JSP、Spring、SpringMVC、MyBatis等,感興趣的小伙伴可以學(xué)習(xí)一下2022-03-03
java實(shí)現(xiàn)獲取安卓設(shè)備里已安裝的軟件包
本文給大家介紹的是如何獲取設(shè)備中已經(jīng)安裝的應(yīng)用軟件包的代碼,其核心方法原理很簡(jiǎn)單,我們通過(guò)Android中提供的PackageManager類,來(lái)獲取手機(jī)中安裝的應(yīng)用程序信息2015-10-10

