private Connection getNewConnection()
{
try
{
this.connection.close();
}
finally
{
this.connection=null;
try
{
Class.forName(this.driverName);
try
{
this.connection=DriverManager.getConnection(this.url,this.userName,
this.password);
}
catch(SQLException e)
{
throw e;
}
}
finally
{
return this.connection;
}
}
}
{
try
{
this.connection.close();
}
finally
{
this.connection=null;
try
{
Class.forName(this.driverName);
try
{
this.connection=DriverManager.getConnection(this.url,this.userName,
this.password);
}
catch(SQLException e)
{
throw e;
}
}
finally
{
return this.connection;
}
}
}
楼主【wufongming】截止到2008-06-26 11:12:24的历史汇总数据(不包括此帖):
发帖数:36 发帖分:1560
结贴数:35 结贴分:1460
未结数:1 未结分:100
结贴率:97.22 % 结分率:93.59 %
值得尊敬
private Connection getNewConnection()
{
try
{
this.connection.close();
}
finally
{
this.connection=null;
try //这个try后面没跟catch或finally
{
Class.forName(this.driverName);
try
{
this.connection=DriverManager.getConnection(this.url,this.userName,
this.password);
}
catch(SQLException e)
{
throw e;
}
}
finally
{
return this.connection;
}
}
}
你这样嵌套也太麻烦了吧.TRY
{}
CATCH(EXCEPTION E)
{
}
FINALLY
{}这样写.不要写嵌套了.一次完成
原因是eclipse认为finally中不应该出现return
如果try{}中有一个return在finally{}中还有一个return
这样try{}中的return就不会执行了
不过LZ的这段代码 不会有任何影响
例如下面的代码public class Test { public static int getReturn() {
try {
return 0;
} finally {
return 1;
}
}
}
private Connection getNewConnection()
{
try
{
this.connection.close();
}
finally
{
this.connection=null;
try
{
Class.forName(this.driverName);
try
{
this.connection=DriverManager.getConnection (this.url,this.userName,this.password);
}
catch(SQLException e)
{
throw e;
}
}
finally
{
return this.connection;
}
}
}
try {
if (this.connection != null) {
this.connection.close();
this.connection = null;
}
Class.forName(this.driverName);
this.connection = DriverManager.getConnection(this.url,
this.userName, this.password);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return this.connection;
}