openPlant实时数据库使用demo

相关依赖

由于没有com.magus.jdbc.jar依赖,需要手动下载防止lib下进行配置

<dependency>
	<groupId>com.magus</groupId>
	<artifactId>jdbc</artifactId>
	<version>3.0</version>
	<scope>system</scope>
	<systemPath>${basedir}/lib/com.magus.jdbc.jar</systemPath>
</dependency>

测试连接demo

public static void main(String[] args) {
		try {
			OPConnect conn = new OPConnect("192.168.2.127", 8300, 60, "sis", "openplant");
			System.out.println(conn.getServerTime());
		} catch (UsersException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

测试查询

public static void main(String[] args) throws InterruptedException,OPException {
		try {
			Class.forName(className);
			Connection conn = DriverManager.getConnection(url, user, password);
			int count = 50000;
			String sql = "select GN from Point limit 0," + count;
			System.out.println("sql:" + sql);

			Statement st = conn.createStatement();
			// for (int i = 0; i < 10; i++) {
			long s = System.currentTimeMillis();
			ResultSet rs = st.executeQuery(sql);
			ResultSetMetaData rsmd = rs.getMetaData();
			for (int i = 1; i <= rsmd.getColumnCount(); i++) {
				System.err.print(rsmd.getColumnLabel(i).toUpperCase() + "\n");
			}
			int t = 0;
			String[] GNs = new String[count];
			while (rs.next()) {
				GNs[t] = "'" + rs.getString(1) + "'";
				t++;
			}
			System.out.println("all count:" + t);
			String gns = "";
			for (int i = 0; i < t; i++) {
				gns += GNs[i];
				if (i < (t - 1)) {
					gns += ",";
				}
			}
			rs.close();
			long e = System.currentTimeMillis();
			System.out.println("用时:" + (e - s));

			sql = "select ID,GN from Point where GN in (" + gns + ")";
			rs = st.executeQuery(sql);
			rsmd = rs.getMetaData();
			for (int i = 1; i <= rsmd.getColumnCount(); i++) {
				System.err.print(rsmd.getColumnLabel(i).toUpperCase() + "\t");
			}
			int i = 0;
			System.err.println("\n");
			while (rs.next()) {
				i++;
				System.err.println(rs.getInt(1) + "\t" + rs.getString(2));
			}
			System.err.println("all count:" + i);
			System.out.println("遍历耗时:" + (System.currentTimeMillis() - e));
			rs.close();
			st.close();

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			OPException ex = new OPException("程序包空间不能与提供的JAR包空间一致");
			throw ex;
		}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值