即使我没有关闭 finally 块,连接也会自动关闭。
public String look( long id, String codeName, Connection conn ) throws SQLException
{
try
{
StringBuffer sel = new StringBuffer().append(property);
stmt = conn.prepareCall( sel.toString() ); /* fileCode.java:194 */
stmt.setString( 1, nameC );
stmt.setLong( 2, valueI );
stmt.registerOutParameter( 3, oracle.jdbc.OracleTypes.VARCHAR );
stmt.execute();
return stmt.getString( 3 );
}
catch ( SQLException e )
{
if ( e.getMessage().toUpperCase().contains( "NO DATA" ) )
{
return "Value not found";
}
throw e;
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
System.out.println( " CONNNNNN closed ? : " + conn.isClosed() );
}
}
方法调用look方法,
public class Verfication
{
public void verify ( , , , , , , ,conn )
{
try
{
if ( x ==1 )
{
ManageCode mCode = new ManageCode();
System.out.println( "----- 1st Call -----" );
String mCodeBlock = mCode.look( , , conn);
String cCodeBlocked = checkBackup ( , , , , , , , , );
/* connection is closed in this part */
System.out.println( "----- 2nd Call -----" );
String nCodeBlock = mCode.look ( , , conn );
}
}catch( )
{
}
}
}
我确实得到了如下所述的输出,我不确定连接有什么问题?我还添加了系统输出。
输出:
----- 1st Call -----
CONNNNNN closed ? : false
----- 2nd Call -----
CONNNNNN closed ? : true
SEVERE: Line:71 CodePointChecker ERROR: java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:839)
at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:802)
at com.XXXXXXXXXXXXXXX.code.fileCode.look(fileCode.java:194)