欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java中的executeQuery()方法使用

 更新時(shí)間:2022年03月23日 14:55:26   作者:Faith_xzc  
這篇文章主要介紹了java中的executeQuery()方法使用,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

java的executeQuery()方法

介紹

使用JDBC連接數(shù)據(jù)庫需要4步:

executeQuery()方法是第四步執(zhí)行查詢;

要用statement類的executeQuery()方法來下達(dá)select指令以查詢數(shù)據(jù)庫,executeQuery()方法會把數(shù)據(jù)庫響應(yīng)的查詢結(jié)果存放在ResultSet類對象中供我們使用。

舉例如下                

String str9 = "select sno from member where sno='" + jt1.getText() + "'"; // 根據(jù)學(xué)號查詢
?? ??? ??? ??? ?String str10 = null;
?? ??? ??? ??? ?try {
?? ??? ??? ??? ??? ?mysql.sql = mysql.con.createStatement();// 插入之前先在數(shù)據(jù)庫里面查
?? ??? ??? ??? ??? ?mysql.res = mysql.sql.executeQuery(str9);//返回查詢結(jié)果
?? ??? ??? ??? ??? ?while (mysql.res.next()) {
?? ??? ??? ??? ??? ??? ?str10 = mysql.res.getString("sno");
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?} catch (SQLException e1) {
?? ??? ??? ??? ??? ?e1.printStackTrace();
?? ??? ??? ??? ?}

executeUpdate()與executeQuery()使用

增、刪、改 用executeUpdate()

返回值為int型,表示被影響的行數(shù)

例子:

查用executeQuery() 返回的是一個(gè)集合

.next()表示 指針先下一行,還有first()指向第一行 、last()指向最后一行、如果有數(shù)據(jù)就返回true

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論