W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
獲得連接后,我們可以使用sql語(yǔ)句與數(shù)據(jù)庫(kù)交互。
通常sql語(yǔ)句由從Connection返回的 Statement
接口執(zhí)行。
JDBC語(yǔ)句
用于通用訪問數(shù)據(jù)庫(kù)。在使用靜態(tài)SQL語(yǔ)句時(shí)非常有用。
Statement接口不能接受參數(shù)。
Statement對(duì)象使用Connection對(duì)象的createStatement()方法創(chuàng)建,如下所示:
Statement stmt = conn.createStatement( );
我們可以使用Statement用它的三個(gè)execute方法之一來(lái)執(zhí)行一個(gè)SQL語(yǔ)句。
boolean execute(String SQL)
int executeUpdate(String SQL)
ResultSet executeQuery(String SQL)
執(zhí)行SELECT語(yǔ)句并返回結(jié)果。返回ResultSet對(duì)象。我們需要關(guān)閉一個(gè) Statement
對(duì)象來(lái)清理分配的數(shù)據(jù)庫(kù)資源。
If we close the Connection object first, it will also close the Statement object.
Statement stmt = null; try { stmt = conn.createStatement( ); stmt execuate method(); } catch (SQLException e) { } finally { stmt.close(); }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: