新聞中心
JDBC4.1更新了兩個(gè)新特性

創(chuàng)新互聯(lián)專注于涪陵網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供涪陵?duì)I銷型網(wǎng)站建設(shè),涪陵網(wǎng)站制作、涪陵網(wǎng)頁(yè)設(shè)計(jì)、涪陵網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造涪陵網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供涪陵網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
1. Connection,ResultSet 和 Statement 都實(shí)現(xiàn)了Closeable 接口,所有在 try-with-resources 語句中調(diào)用,就可以自動(dòng)關(guān)閉相關(guān)資源了
Java代碼
- try (Statement stmt = con.createStatement()){
- …
- }
2. RowSet 1.1:引入RowSetFactory接口和RowSetProvider類,可以創(chuàng)建JDBC driver支持的各種 row sets
Java代碼
- RowSetFactory myRowSetFactory = null;
- JdbcRowSet jdbcRs = null;
- ResultSet rs = null;
- Statement stmt = null;
- try {
- myRowSetFactory = RowSetProvider.newFactory();//用缺省的RowSetFactory 實(shí)現(xiàn)
- jdbcRs = myRowSetFactory.createJdbcRowSet();
- //創(chuàng)建一個(gè) JdbcRowSet 對(duì)象,配置數(shù)據(jù)庫(kù)連接屬性
- jdbcRs.setUrl("jdbc:myDriver:myAttribute");
- jdbcRs.setUsername(username);
- jdbcRs.setPassword(password);
- jdbcRs.setCommand("select ID from TEST");
- jdbcRs.execute();
- }
RowSetFactory 接口包括了創(chuàng)建不同類型的RowSet的方法
?createCachedRowSet
?createFilteredRowSet
?createJdbcRowSet
?createJoinRowSet
?createWebRowSet
參考資料
Jdk7官網(wǎng) http://openjdk.java.net/projects/jdk7/
(注:這篇文章發(fā)表時(shí),JDK7未正式公布,可能有誤差,具體以官方正式版為準(zhǔn))
當(dāng)前標(biāo)題:探秘JDK7新特性之JDBC4.1
鏈接URL:http://m.5511xx.com/article/cocdjsc.html


咨詢
建站咨詢
