//獲取字段值,參數(shù)為字符串--字段名
publicStringgetString(StringfieldName)
throwsSQLException{
returnrs.getString(fieldName);
}
//上移指針
publicbooleanprevious()
throwsSQLException{
if(rs==null)
thrownewSQLException("ResultSetisnull.");
returnrs.previous();
}
//下移指針
publicbooleannext()
throwsSQLException{
if(rs==null)
thrownewSQLException("ResultSetisnull.");
returnrs.next();
}
//指針最上
publicbooleanfirst()
throwsSQLException{
if(rs==null)
thrownewSQLException("ResultSetisnull.");
returnrs.first();
}
//指針最下
publicbooleanlast()
throwsSQLException{
if(rs==null)
thrownewSQLException("ResultSetisnull.");
returnrs.last();
}
//清除變量,當(dāng)你僅需要清除變量而不關(guān)庫時(shí)可調(diào)用此方法
privatevoidclear()throwsSQLException{
if(rs!=null)rs.close();
rs=null;
if(stmt!=null)stmt.close();
stmt=null;
}
//清除變量并關(guān)庫
publicvoidclose()throwsSQLException{
clear();
if(conn==null)
thrownewSQLException("Thisconnectionhasbeenclosedalready.");
if(conn.isClosed())
thrownewSQLException("Thisconnectionhasbeenclosed.");
conn.close();
conn=null;
}
}
2編寫邏輯層代碼
##在客戶端創(chuàng)建dbbridge.jsp,然后上傳到服務(wù)器端即可:
##上級(jí)要來視察某官僚的工作,只見該官僚指揮若定:
##邏輯層對(duì)處理層說:小子,去跟我的后臺(tái)聯(lián)絡(luò)一下。//連庫并初始化
<jsp:useBeanid="bridge"class="com.gledecity.yesgo.sql.DBBridge"/>
##邏輯層對(duì)處理層說:把我們今年的工作成果準(zhǔn)備一下。//執(zhí)行SQL語句
<%bridge.execSQL("select*fromprov");
##邏輯層對(duì)處理層說:材料準(zhǔn)備好了?干得好!上級(jí)一來看到一片數(shù)據(jù)。//循環(huán)顯示
while(bridge.next())
{out.print(bridge.getString("prov_id")+bridge.getString("prov_name")+"<br>");}
##邏輯層對(duì)處理層說:好了好了,政績(jī)顯示完畢,你們通通滾蛋吧。//關(guān)閉所有變量
bridge.close();%>
##上級(jí)看后非常滿意,拍拍官僚的肩膀:"干得不錯(cuò)!"官僚一高興,說:"哪里哪里,都是下屬辦事得力!"
3測(cè)試該程序
lynxhttp://www.yesgo.loc/dbbridge.jsp
##當(dāng)然你也可以在客戶端瀏覽器測(cè)試,只是你需要將你服務(wù)器的IP添加到你網(wǎng)絡(luò)設(shè)置中的DNS列表中。
##處理的結(jié)果是數(shù)據(jù)庫中所有的數(shù)據(jù):
1安徽
2北京
3重慶
4福建
5甘肅
6廣東
7廣西
8貴州
9海南
10河北
11黑龍江
12河南
13湖北
14湖南
15內(nèi)蒙古
16江蘇
17江西
18吉林
19遼寧
20寧夏
21青海
22山西
23陜西
24山東
25上海
26四川
27天津
28西藏
29新疆
30云南
31浙江
32香港
33澳門
34臺(tái)灣
例四:測(cè)試PHP
1創(chuàng)建源文件
touch/home/www/test.php
chmod701/home/www/test.php
2編輯源文件
vitest.php
##源代碼如下:
<?
phpinfo();
?>
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注