try-with-resources的使用问题 这货木有人用过么?jdk7还不是太普及阿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 OH jdk7还真没有用过。好像增加了不少新的东西。ResutlSet肯定是需要关闭的嘛,这能有什么问题呢? JDK7新增的try-with-resources是用来自动关闭资源的,只要这个资源类型接口AutoCloseable....所以才出现我提的问题。 你不关闭肯定会这样啊。。一定要关闭 最好放在finally块里 换个数据库试试,看看是jre的问题,还是M$ jdbc驱动的问题 请看清问题内容再说....应该跟这个没啥关系吧,实现是通过接口AutoCloseable的close方法来做的,显示调用和隐式调用同一个类型的同一个方法结果可能不同么? public static void viewTable(Connection con) throws SQLException { String query = "select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES"; 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); } }看官方例子http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html不知道你代码是不是写错了. 它和我唯一的不同就是他用的资源是Statement,我用的是ResultSet。这俩类型在jdk7里面都增加了接口AutoCloseable,所以在这里作为一个资源的作用应该是等效的。 按创建顺序关闭,之前的也要写在try(^^^^^^^)中,一次关闭 泛型类??? Java正则表达式"句号"问题 用浏览器和appletviewer命令查看Applet的区别 异常捕捉不到,请指教! 基础问题:请问如下一行语句的意思? 关于获取在jsp上获取客户端时间的问题 在使用中,经常出现提示为:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]连接占线导致另一个 hstmt,是什么意思,怎样解 请各位帮忙 textpad + jdk 提示错误! 求助一个C#用AES加密,java解密的问题 这个异常怎么解决呀 ant的taskdef怎么使用
应该跟这个没啥关系吧,实现是通过接口AutoCloseable的close方法来做的,显示调用和隐式调用同一个类型的同一个方法结果可能不同么?
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);
}
}
看官方例子
http://docs.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html不知道你代码是不是写错了.