[php] con = DriverManager.getConnection(url);
//获取数据库的元数据
dma =con.getMetaData();
//将数据库中的表的名称转储出来
String[] types = new String[1];
types[0] = "TABLES"; //设置查询类型
//请注意通配符是
% 符号(而不是
“*”)
results = dma.getTables(null, null, "%", types);
[/php]
这里的get_tables会产生一个statement(从数据库能看到一个打开的游标)
如果connection不能关闭的情况下,这个statement如何关闭?
使用连接池的话连接是不会被物理close的
这里又没有声明statement所以也不能close statement
关闭resultset不能关闭statement
for(int i=0;i<10;i++){
DatabaseMetaData dma =con.getMetaData();
ResultSet rs1 =dma.getTables(null,"CJSX","%",new String[]{"TABLE"});
rs1.close;
}
这里如果注掉rs1.close会开10个游标(开发人员犯了这个错误,当然没有直接循环这么明显,由于使用了连接池,长时间累计后导致游标泄漏)
否则开一个,直到con.close
[QUOTE][i]最初由 iooyoo 发布[/i]
[B]if( rs.getstatement() != null)
rs.getstatement().close(); [/B][/QUOTE]
[php]
public static void testgettables1()throws SQLException
{
Connection con = null;
try {
con = getConnection();
DatabaseMetaData dma =con.getMetaData();
ResultSet rs1 =dma.getTables(null,"CJSX","%","TABLE");
while (rs1.next()) {
}
rs1.close();
rs1.getStatement().close();
try{
System.out.println("等待100秒关闭con,此时查询opencursor情况.....");
Thread.sleep(100000);
con.close();
}catch (InterruptedException e) {
System.out.println("等待100秒出错!");
}
}
finally {
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
}
}
}
[/php]
上面的代码执行等待时去查询v$open_cursor仍会发现gettables打开的游标:
[php]
SELECT NULL AS table_cat,
o.owner AS table_schem,
o.object_name AS table_name,
o.object_type AS table_type,
NULL AS remarks
FROM all_objects o
WHERE o.owner LIKE :1
AND o.object_name LIKE :2
AND o.object_type IN ('xxx', 'TABLE')
ORDER BY table_type, table_schem, table_name
[/php]
没有关闭
//获取数据库的元数据
dma =con.getMetaData();
//将数据库中的表的名称转储出来
String[] types = new String[1];
types[0] = "TABLES"; //设置查询类型
//请注意通配符是
% 符号(而不是
“*”)
results = dma.getTables(null, null, "%", types);
[/php]
这里的get_tables会产生一个statement(从数据库能看到一个打开的游标)
如果connection不能关闭的情况下,这个statement如何关闭?
使用连接池的话连接是不会被物理close的
这里又没有声明statement所以也不能close statement
关闭resultset不能关闭statement
for(int i=0;i<10;i++){
DatabaseMetaData dma =con.getMetaData();
ResultSet rs1 =dma.getTables(null,"CJSX","%",new String[]{"TABLE"});
rs1.close;
}
这里如果注掉rs1.close会开10个游标(开发人员犯了这个错误,当然没有直接循环这么明显,由于使用了连接池,长时间累计后导致游标泄漏)
否则开一个,直到con.close
[QUOTE][i]最初由 iooyoo 发布[/i]
[B]if( rs.getstatement() != null)
rs.getstatement().close(); [/B][/QUOTE]
[php]
public static void testgettables1()throws SQLException
{
Connection con = null;
try {
con = getConnection();
DatabaseMetaData dma =con.getMetaData();
ResultSet rs1 =dma.getTables(null,"CJSX","%","TABLE");
while (rs1.next()) {
}
rs1.close();
rs1.getStatement().close();
try{
System.out.println("等待100秒关闭con,此时查询opencursor情况.....");
Thread.sleep(100000);
con.close();
}catch (InterruptedException e) {
System.out.println("等待100秒出错!");
}
}
finally {
try {
if (con != null) {
con.close();
}
} catch (Exception e) {
}
}
}
[/php]
上面的代码执行等待时去查询v$open_cursor仍会发现gettables打开的游标:
[php]
SELECT NULL AS table_cat,
o.owner AS table_schem,
o.object_name AS table_name,
o.object_type AS table_type,
NULL AS remarks
FROM all_objects o
WHERE o.owner LIKE :1
AND o.object_name LIKE :2
AND o.object_type IN ('xxx', 'TABLE')
ORDER BY table_type, table_schem, table_name
[/php]
没有关闭
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27378/viewspace-605951/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27378/viewspace-605951/