关闭游标数,,finally里关闭

web_backend_develope
chenlw 8 years ago
parent 9379020534
commit 582f55a619

@ -152,13 +152,21 @@ public class OracleConnector {
flag = true; flag = true;
FileOperateHelper.fileWrite(filePath + ".log", "执行结果:" + res FileOperateHelper.fileWrite(filePath + ".log", "执行结果:" + res
+ " \r\n"); + " \r\n");
statement.close();
} catch (SQLException e) { } catch (SQLException e) {
flag = false; flag = false;
FileOperateHelper.fileWrite(filePath + ".log", FileOperateHelper.fileWrite(filePath + ".log",
e.getMessage() + "\r\n"); e.getMessage() + "\r\n");
log.error(Custom4exception.OracleSQL_Except, e); log.error(Custom4exception.OracleSQL_Except, e);
} }
finally {
if (null != statement) {
try {
statement.close();
} catch (SQLException e) {
log.error(Custom4exception.OracleSQL_Except, e);
}
}
}
return flag ; return flag ;
} }
@ -184,7 +192,7 @@ public class OracleConnector {
flag = true; flag = true;
FileOperateHelper.fileWrite(filePath + ".log", "执行结果:"+ res FileOperateHelper.fileWrite(filePath + ".log", "执行结果:"+ res
+ " \r\n"); + " \r\n");
statement.close();
if (res < 1) { if (res < 1) {
flag = false; flag = false;
} }
@ -195,6 +203,16 @@ public class OracleConnector {
e.getMessage() + "\r\n"); e.getMessage() + "\r\n");
log.error(Custom4exception.OracleSQL_Except, e); log.error(Custom4exception.OracleSQL_Except, e);
} }
finally{
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return flag; return flag;
} }
} }

@ -46,7 +46,6 @@ public class OracleExtractHelper {
} }
FileOperateHelper.fileWrite(filePath + ".log", sql + "\r\n" FileOperateHelper.fileWrite(filePath + ".log", sql + "\r\n"
+ "OK \r\n"); + "OK \r\n");
statement.close();
} catch (Exception e) { } catch (Exception e) {
FileOperateHelper.fileWrite(filePath, sql + "\r\n" + e.getMessage() FileOperateHelper.fileWrite(filePath, sql + "\r\n" + e.getMessage()
@ -288,10 +287,18 @@ public class OracleExtractHelper {
log.error(Custom4exception.threadVolume_Oracle_Except, e); log.error(Custom4exception.threadVolume_Oracle_Except, e);
} }
} }
statement.close();
} catch (SQLException e) { } catch (SQLException e) {
log.error(Custom4exception.threadVolume_Oracle_Except, e); log.error(Custom4exception.threadVolume_Oracle_Except, e);
} }
finally {
if (null != statement) {
try {
statement.close();
} catch (SQLException e) {
log.error(Custom4exception.OracleSQL_Except, e);
}
}
}
} }
@ -303,15 +310,24 @@ public class OracleExtractHelper {
public boolean testConnect(Connection conn) { public boolean testConnect(Connection conn) {
String testSql = "select count(*) from user_tables"; String testSql = "select count(*) from user_tables";
boolean flag = false; boolean flag = false;
Statement statement = null;
try { try {
Statement statement = conn.createStatement(); statement = conn.createStatement();
if (statement.executeUpdate(testSql) > 0) if (statement.executeUpdate(testSql) > 0)
flag = true; flag = true;
statement.close();
} catch (SQLException e) { } catch (SQLException e) {
flag = false; flag = false;
log.error(Custom4exception.threadVolume_Oracle_Except, e); log.error(Custom4exception.threadVolume_Oracle_Except, e);
} }
finally {
if (null != statement) {
try {
statement.close();
} catch (SQLException e) {
log.error(Custom4exception.OracleSQL_Except, e);
}
}
}
return flag; return flag;
} }

@ -0,0 +1,20 @@
package com.platform.test;
public class testStateThread {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
Thread t1 = new Thread(new testStatement(), "线程-"+i);
t1.setDaemon(true);
t1.start();
}
try {
Thread.sleep(50000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -0,0 +1,63 @@
package com.platform.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class testStatement implements Runnable{
private static Connection createConnect() {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.110:1590:ORCL", "system", "oracle");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
@Override
public void run() {
Connection conn = createConnect();
for(int i=0;i<1000;i++)
{
Statement prepstmt = null;
try {
// PreparedStatement prepstmt = conn.prepareStatement("select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = 'ORCL'");
// int numi = prepstmt.executeUpdate();
prepstmt = conn.createStatement();
int numi = prepstmt.executeUpdate("select TABLESPACE_NAME from dba_tablespaces where TABLESPACE_NAME = 'ORCL'");
System.out.println(Thread.currentThread().getName()+" "+i +" : "+ numi);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if (prepstmt != null) {
try {
prepstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}
Loading…
Cancel
Save