所有的connection都放入 finally块 关闭

web_backend_develope
chenlw 8 years ago
parent 582f55a619
commit 1a2cffab4d

@ -2,6 +2,8 @@ package com.platform.service;
import java.sql.SQLException;
import com.base.CustomException;
import com.platform.entities.OracleConnectorParams;
import com.platform.oracle.OracleConnector;
@ -19,6 +21,14 @@ public class OracleExtractService extends Thread implements Runnable {
} catch (CustomException e) {
this.conn = null;
}
finally{
try {
this.conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void run() {

@ -1,6 +1,7 @@
package com.platform.service;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
@ -45,9 +46,10 @@ public class OracleExtractTask extends AbstractOracleExtractTask {
@Override
public void handler() {
Connection conn = null;
// TODO Auto-generated method stub
try {
Connection conn = OracleConnector.connectionBuilder(
conn = OracleConnector.connectionBuilder(
createConnectUrl(), gatherOracleInfo.getUser(),
gatherOracleInfo.getPassword(), oc);
if (null != conn) {
@ -90,11 +92,19 @@ public class OracleExtractTask extends AbstractOracleExtractTask {
.date2StringBysecond(new Date())
+ "]>>>>>>>>>>>>>>>>汇总结束 >>>>>>>>>>>>>>>>>>\r\n\r\n");
OracleExtract.updateDataExtractStatus(oc, 2); // 更新数据库的状态
conn.close(); // 关闭连接
}
} catch (Exception e) {
log.error(Custom4exception.OracleSQL_Except, e);
}
finally{
if(conn != null)
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // 关闭连接
}
}
private String createConnectUrl() {

@ -1,6 +1,7 @@
package com.platform.service.impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
@ -56,6 +57,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
List<OracleConnectorParams> datainfos, GatherOracleInfo oracleModel)
throws Exception {
boolean isSuccess = false;
Connection conn = null;
try {
// map转 bean(汇总库信息-带tableName的)
// GatherOracleInfo oracleModel = oracleConnect;
@ -64,7 +66,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
if (datainfos.size() == 0) {
return false;
}
Connection conn = OracleConnector.connectionBuilder(
conn = OracleConnector.connectionBuilder(
"jdbc:oracle:thin:@" + oracleModel.getIp() + ":"
+ oracleModel.getPort() + ":"
+ oracleModel.getDatabaseName(),
@ -172,6 +174,16 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
} catch (Exception e) {
new CustomException(Custom4exception.OracleSQL_Except, e);
}
finally{
if(conn != null){
try {
conn.close();
} catch (SQLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
return isSuccess;
}
@ -179,7 +191,10 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
public boolean isConnectTotalOracle(GatherOracleInfo oracleModel)
throws Exception {
boolean isConnect = false;
Connection conn = OracleConnector.connectionBuilder(
Exception excep = null;
Connection conn = null;
try {
conn = OracleConnector.connectionBuilder(
"jdbc:oracle:thin:@" + oracleModel.getIp() + ":"
+ oracleModel.getPort() + ":"
+ oracleModel.getDatabaseName(), oracleModel.getUser(),
@ -193,7 +208,21 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
// "]\r\n");
} else {
isConnect = oracleExtract.testConnect(conn);
}
} catch (Exception e) {
excep = e;
}
finally{
if(conn != null){
try {
conn.close();// 关闭连接
} catch (Exception e2) {
// TODO: handle exception
}
}
if (excep != null) {
throw excep;
}
}
return isConnect;
}
@ -201,7 +230,7 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
@Override
public boolean extractStandardTable(String name,
List<OracleConnectorParams> dataInfolist,
GatherOracleInfo oracleConnect) throws Exception {
GatherOracleInfo oracleConnect) {
boolean isSuccess = false;
// map转 bean(汇总库信息-带tableName的)
GatherOracleInfo oracleModel = oracleConnect;
@ -210,7 +239,9 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
if (datainfos.size() == 0) {
return false;
}
Connection conn = OracleConnector.connectionBuilder(
Connection conn = null;
try {
conn = OracleConnector.connectionBuilder(
"jdbc:oracle:thin:@" + oracleModel.getIp() + ":"
+ oracleModel.getPort() + ":"
+ oracleModel.getDatabaseName(), oracleModel.getUser(),
@ -360,6 +391,19 @@ public class OracleExtractServiceImpl implements IOracleExtractService {
+ "\r\n\r\n\n");
}
}
} catch (Exception e) {
// TODO: handle exception
}
finally{
if(conn != null){
try {
conn.close();// 关闭连接
} catch (Exception e2) {
// TODO: handle exception
}
}
}
isSuccess = true;
return isSuccess;
}

@ -231,8 +231,9 @@ public class ThreadCheckoutStandardOracle extends Thread {
String logName = tmp.getAreaCode().toLowerCase() + "_"
+ tmp.getSysCode() + "_" + tmp.getDataVersion();
oc.setName(logName);
Connection conn = null;
try {
Connection conn = OracleConnector.connectionBuilder(
conn = OracleConnector.connectionBuilder(
url, Configs.ORACLE_USER, Configs.ORACLE_PSW,
oc);
// 支付--校验
@ -304,6 +305,15 @@ public class ThreadCheckoutStandardOracle extends Thread {
} catch (Exception e) {
log.error(e);
}
finally{
if(conn != null){
try {
conn.close();// 关闭连接
} catch (Exception e2) {
// TODO: handle exception
}
}
}
// 成功 就 清除 CacheOracleCheckoutEntity 中 的该条记录
CacheOracleCheckoutEntity.checkRemove(key);
}

Loading…
Cancel
Save