亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何查找ResultSet.next()方法的jdk源代碼

如何查找ResultSet.next()方法的jdk源代碼

慕斯709654 2018-10-09 18:10:09
今天在做一個數據庫查詢的時候遇到一個關于ResultSet.next()方法的問題。在查詢出結果集以后,如果我先調用一次ResultSet.next()以后,再次調用ResultSet.next()就會出現空指針異常。代碼如下:pstm3 = connection.prepareStatement(sql2);        rsResult = pstm3.executeQuery();         boolean flag=rsResult.next();          System.err.println(flag+"------");         if (rsResult.next()) {                     jysString = rsResult.getString(6);         }如果我直接循環結果集就沒有問題:pstm3 = connection.prepareStatement(sql2);        rsResult = pstm3.executeQuery();         if (rsResult.next()) {                     jysString = rsResult.getString(6);         }所以,我就想看ResultSet.next()方法是怎么實現的,在eclipse中我點進去這個方法,卻發現這只是一個接口boolean next() throws SQLException;所以我想問一下,ResultSet.next()的機制是什么樣的,怎么在eclipse中查看它的源代碼?謝謝各位
查看完整描述

2 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

點進去是接口,說明jdk只定義了接口,源碼需要第三方自己實現,類似servlet的api,根據不同的第三方服務提供商,實現也會有差異。如果你用的數據庫是mysql,ResultSet的具體實現可以在mysql-connector-java.jar這種第三方jar里找

查看完整回答
反對 回復 2018-10-29
?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

A ResultSet is initially positioned before its first row, the first
call to next makes the first row the current row; the second call
makes the second row the current row, etc. If an input stream from the
previous row is open, it is implicitly closed. The ResultSet's warning
chain is cleared when a new row is read

上面是文檔的描述,意思是當你調用一次next()的時候,游標即文中提到的position會往下移動。


查看完整回答
反對 回復 2018-10-29
  • 2 回答
  • 0 關注
  • 859 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號