以下示例使用try-with-resources语句自动关闭java.sql.Statement对象:
jQuery("#bildo_mc_form").submit(function(e){
console.log("form submitted");
function callbackFunction(data){
window.location.href = "http://thanks.com";
console.log("sucess result" + data.result);
console.log("sucess msg" + data.msg);
}
var url = jQuery(this).prop('action'); // the script where you handle the form input.
jQuery.ajax({
type: "GET",
url: url,
data: jQuery("#bildo_mc_form").serialize(), // serializes the form's elements.
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
error: function(error){
// According to jquery docs, this is never called for cross-domain JSONP requests
console.log("Error Result" + error.result);
},
success: callbackFunction
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
该文件未提及try (Statement stmt = con.createStatement()) {
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + ", " + supplierID + ", " +
price + ", " + sales + ", " + total);
}
} catch (SQLException e) {
JDBCTutorialUtilities.printSQLException(e);
}
。我知道ResultSet
始终没有关闭,导致连接泄漏。我的理解是否正确?