|
|
package com.sitech.ismp.coll;
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.DriverManager;
|
|
|
import java.sql.PreparedStatement;
|
...
|
...
|
@@ -10,8 +12,6 @@ import java.util.HashMap; |
|
|
import java.util.Map;
|
|
|
import java.util.Vector;
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
public class SQLTarget extends CollBase {
|
|
|
Logger logger = Logger.getLogger(SQLTarget.class);
|
|
|
String ObjectIP = null;
|
...
|
...
|
@@ -189,19 +189,31 @@ public class SQLTarget extends CollBase { |
|
|
Vector recordSet = new Vector();
|
|
|
PreparedStatement pstmt = null;
|
|
|
ResultSet result = null;
|
|
|
try {
|
|
|
if (!getState()) {
|
|
|
return recordSet;
|
|
|
}
|
|
|
if (!getState()) {
|
|
|
return recordSet;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
pstmt = dbConnection.prepareStatement(sql);
|
|
|
boolean hasResult = pstmt.execute();
|
|
|
} catch (SQLException e) {
|
|
|
throw new RuntimeException("Exception while exec sql :" + sql, e);
|
|
|
}
|
|
|
|
|
|
boolean hasResult = false;
|
|
|
try {
|
|
|
hasResult = pstmt.execute();
|
|
|
} catch (SQLException e) {
|
|
|
logger.error("pstmt.execute() has error!",e);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
try {
|
|
|
|
|
|
if (hasResult) {
|
|
|
result = pstmt.getResultSet();
|
|
|
ResultSetMetaData rsmd = result.getMetaData();
|
|
|
int iColumnCount = rsmd.getColumnCount();
|
|
|
while (result.next()) {
|
|
|
java.util.Vector vTemp = new Vector();
|
|
|
Vector vTemp = new Vector();
|
|
|
for (int i = 0; i < iColumnCount; i++) {
|
|
|
Object oTemp = result.getObject(i + 1);
|
|
|
String sTemp = oTemp == null ? "" : oTemp.toString();
|
...
|
...
|
@@ -212,14 +224,9 @@ public class SQLTarget extends CollBase { |
|
|
result.close();
|
|
|
}
|
|
|
pstmt.close();
|
|
|
// if (!"MySQL".equals(DBType)) {
|
|
|
// dbConnection.commit();
|
|
|
// }
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException("Exception while exec sql :" + sql, e);
|
|
|
} finally {
|
|
|
// releaseResources();
|
|
|
|
|
|
try {
|
|
|
if(pstmt!=null){
|
|
|
pstmt.close();
|
...
|
...
|
@@ -239,11 +246,11 @@ public class SQLTarget extends CollBase { |
|
|
getConnection();
|
|
|
try {
|
|
|
if (!state) {
|
|
|
java.lang.Thread.sleep(5000);// 间隔5s重试第二次连接
|
|
|
Thread.sleep(5000);// 间隔5s重试第二次连接
|
|
|
System.err.println("--second--conn error----");
|
|
|
getConnection();
|
|
|
if (!state) {
|
|
|
java.lang.Thread.sleep(5000);// 再间隔5s重试第三次连接
|
|
|
Thread.sleep(5000);// 再间隔5s重试第三次连接
|
|
|
System.err.println("--third--conn error----");
|
|
|
getConnection();
|
|
|
}
|
...
|
...
|
@@ -326,8 +333,11 @@ public class SQLTarget extends CollBase { |
|
|
return kpiinfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 释放数据库连接
|
|
|
*/
|
|
|
public void release() {
|
|
|
// releaseResources();
|
|
|
releaseResources();
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|