{请您活用编辑功能}
看见一段代码:
A.class
protected static Connection getConnection()
throws Exception
{
Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
return DriverManager.getConnection("...", "scott","tiger");
}
public static ResultSet getResultSet(String tableName)
throws Exception
{
if (tableName == null)
throw new Exception();
Connection conn = getConnection();
if (conn == null)
throw new Exception();
String sql = "select * from " + tableName;
Statement stmt = conn.createStatement();
return stmt.executeQuery(sql);
}
B.class
private void getRS()
{
try
{
rs = A.getResultSet("test");
if (rs == null)
throw new Exception();
} catch (Exception e)
{
e.printStackTrace();
}
}
难道Connection、ResultSet就可以不用关闭了吗?
望大虾指定迷津。