相关依赖
由于没有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;
}