通过JAVA连接PI实时数据库

PI数据库开发SDK例程 The introduction provides an architectural overview of how the PI-SDK fits into various programming environments. A description and simplified view of the PI-SDK object model is also presented. What Is the PI-SDK? The PI Software Development Kit (PI-SDK) is a programming tool providing access to PI Servers. The software consists of an ActiveX in-process server, an ActiveX control, and supporting code libraries. The kit comes with online documentation, example code, various support files, and tools. The PI-SDK runs on 32-bit Windows platforms and provides access to servers on all PI platforms. Based on Microsoft’s Component Object Model (COM), the PI-SDK can be used with most WIN32 programming environments. The kit is particularly well integrated with Microsoft Visual Basic providing rapid development and deployment of PI applications. The PI-SDK provides an object-oriented approach to program interaction with PI Systems. It delivers a hierarchical model of objects and collections representing the components of PI Servers. This approach provides for intuitive and efficient access. What Documentation Is Provided? The PI-SDK User Guide and the PI-SDK Programming Reference are the primary sources for information related to the PI-SDK. Both are incorporated in the online help system. A version of the user guide in MS Word format is also installed during the setup for printing or for use in training programs. Programming Reference Detailed programming references for properties and methods of each object in the PI-SDK and the PI-SDK Control and Dialogs are available in online help. Most methods provide an example of their usage in Visual Basic. Other code examples, including examples of calling the PI-SDK
Java连接pi数据库可以使用JDBCJava Database Connectivity)API实现。首先需要下载并添加Pi JDBC驱动程序到项目中。然后编写连接程序,首先要生成一个数据库连接对象,接着再通过getConnection()方法来建立连接。具体实现可以参照以下步骤: 1.下载并添加Pi JDBC驱动程序到项目中。 2.在Java程序中通过Class.forName()方法加载数据库驱动类。 3.建立连接,使用DriverManager.getConnection()方法获取Connection对象。 4.通过Connection对象创建Statement对象,并通过execute()方法对数据库进行操作。 以下是Java连接pi数据库的示例代码: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class PiDatabaseConnection { public static void main(String[] args) { Connection connection = null; Statement statement = null; ResultSet resultSet = null; try { //加载数据库驱动 Class.forName("com.osisoft.jdbc.Driver"); //建立连接 connection = DriverManager.getConnection("jdbc:pisql://<Pi_DataArchive>:1/PiServer", "user", "password"); //创建Statement对象 statement = connection.createStatement(); //查询数据库 resultSet = statement.executeQuery("SELECT * FROM piarchive..piinterp WHERE tag='sinusoid' AND time BETWEEN '*-1h' AND '*'"); //对结果集进行处理 while (resultSet.next()) { System.out.println(resultSet.getString(1) + " " + resultSet.getString(2)); } } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); } finally { //关闭连接和Statement对象以及ResultSet对象 try { if (resultSet != null) resultSet.close(); if (statement != null) statement.close(); if (connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } ``` 注:需要替换代码中的`<Pi_DataArchive>`、`user`和`password`为实际的数据存档名、用户名和密码。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值