Sign-up....

调用bean里的close()方法关闭Connection会出错,这是为什么?

openMyOracle.class源文件:

------------------------------------------------------------------------------------

import java.lang.*;

import java.sql.*;

//调用数据库的openMyOracle类

public class openMyOracle{

private String sDBDriver = "oracle.jdbc.driver.OracleDriver";

[293 byte] By [msdn] at [2007-9-21 9:34:14]
# 1 Re: 调用bean里的close()方法关闭Connection会出错,这是为什么?
最好不要将connection 和close()分开,使用完毕就关闭,这样不容易出问题。

Connection conn = null;

try{

....

rs.close();

stmt.close();

.....

}catch(Exception e){}

finally{

if(conn!=null)

try{

conn.close();

}catch(Exception e){}

}

lecy at 2005-01-07 11:34:00 >
# 2 Re: 调用bean里的close()方法关闭Connection会出错,这是为什么?
楼上的兄弟,如果照你这么做,那么结果集就返回不了了。因为执行try里的内容后就要关闭connection,那结果集也没有了,会取不出数据。
tiangeng at 2005-01-07 11:36:00 >
# 3 Re: 调用bean里的close()方法关闭Connection会出错,这是为什么?
在rs关闭前,把rs内容转到一个对象中,等conn.close()以后返回对象。
gohands at 2005-01-07 13:20:00 >

Web

All Classified