方式一:
ResultSet rs = ....;
try {
if (rs != null) {
while (rs.next()) {
rs.getString(1);
....;
}
}
} catch (SQLException e) {
.....
} 方式二:
public class SelectResult {
private ResultSet rs = null;
//....
public SelectResult( ResultSet rs) {
this.rs = rs;
}
public boolean next() {
try {
return rs.next();
} catch (SQLException e) {
.........;
}
}
}
//
while (SelectResult.next()) {
//....
}
是不是放在一起全部来catch比较效率好?而不是把try/catch放在一个函数中来循环调用?这样效率会差多少呢?
ResultSet rs = ....;
try {
if (rs != null) {
while (rs.next()) {
rs.getString(1);
....;
}
}
} catch (SQLException e) {
.....
} 方式二:
public class SelectResult {
private ResultSet rs = null;
//....
public SelectResult( ResultSet rs) {
this.rs = rs;
}
public boolean next() {
try {
return rs.next();
} catch (SQLException e) {
.........;
}
}
}
//
while (SelectResult.next()) {
//....
}
是不是放在一起全部来catch比较效率好?而不是把try/catch放在一个函数中来循环调用?这样效率会差多少呢?
不过推荐在一个try中包含尽可能多的可捕获异常
方法二中next() 显的多余