//獲取字段值,參數為字符串--字段名
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();
}
//清除變量,當你僅需要清除變量而不關庫時可調用此方法
privatevoidclear()throwsSQLException{
if(rs!=null)rs.close();
rs=null;
if(stmt!=null)stmt.close();
stmt=null;
}
//清除變量并關庫
publicvoidclose()throwsSQLException{
clear();
if(conn==null)
thrownewSQLException("Thisconnectionhasbeenclosedalready.");
if(conn.isClosed())
thrownewSQLException("Thisconnectionhasbeenclosed.");
conn.close();
conn=null;
}
}
2編寫邏輯層代碼
##在客戶端創建dbbridge.jsp,然后上傳到服務器端即可:
##上級要來視察某官僚的工作,只見該官僚指揮若定:
##邏輯層對處理層說:小子,去跟我的后臺聯絡一下。//連庫并初始化
<jsp:useBeanid="bridge"class="com.gledecity.yesgo.sql.DBBridge"/>
##邏輯層對處理層說:把我們今年的工作成果準備一下。//執行SQL語句
<%bridge.execSQL("select*fromprov");
##邏輯層對處理層說:材料準備好了?干得好!上級一來看到一片數據。//循環顯示
while(bridge.next())
{out.print(bridge.getString("prov_id")+bridge.getString("prov_name")+"<br>");}
##邏輯層對處理層說:好了好了,政績顯示完畢,你們通通滾蛋吧。//關閉所有變量
bridge.close();%>
##上級看后非常滿意,拍拍官僚的肩膀:"干得不錯!"官僚一高興,說:"哪里哪里,都是下屬辦事得力!"
3測試該程序
lynxhttp://www.yesgo.loc/dbbridge.jsp
##當然你也可以在客戶端瀏覽器測試,只是你需要將你服務器的IP添加到你網絡設置中的DNS列表中。
##處理的結果是數據庫中所有的數據:
1安徽
2北京
3重慶
4福建
5甘肅
6廣東
7廣西
8貴州
9海南
10河北
11黑龍江
12河南
13湖北
14湖南
15內蒙古
16江蘇
17江西
18吉林
19遼寧
20寧夏
21青海
22山西
23陜西
24山東
25上海
26四川
27天津
28西藏
29新疆
30云南
31浙江
32香港
33澳門
34臺灣
例四:測試PHP
1創建源文件
touch/home/www/test.php
chmod701/home/www/test.php
2編輯源文件
vitest.php
##源代碼如下:
<?
phpinfo();
?>
3測試該程序
lynxhttp://www.yesgo.loc/test.php
//結果是大家熟知的服務器端變量列表。
Step17Configurationdebug
##調試過程可能的錯誤如下:
常見錯誤一:Youdon'thavepermission
Forbidden
Youdon'thavepermissiontoaccess/onthisserver.
Apache/1.3.22Serveratwww.yesgo.locPort80
原因可能是:
1、你沒有為該目錄或者該文件設置guest組權限;
2、你沒有將該文件名設置為默認頁面,尤其是在僅用域名訪問的情況下。
解決辦法:
chmod701/home/www
chmod701/home/www/*
vi/usr/local/apache/conf/httpd.conf
DirectoryIndexindex.htmlindex.jspindex.xtpindex.phpindex.php3
常見錯誤二:404NotFound
404NotFound
/index.jspwasnotfoundonthisserver.
Resin2.0.5(builtThuNov1517:56:24PST2001)
原因可能是:
1、你請求的文件名輸入錯誤;
2、你沒有在resin.conf和httpd.conf中都建立相應的主機。
解決辦法:
1、檢查文件名,尤其注意大小寫問題;
2、參照Resininstall步驟中的配置支持JSP的虛擬主機部分。
常見錯誤三:java.lang.ClassNotFoundException
500ServletException
java.lang.ClassNotFoundException:org.gjt.mm.mysql.Driver
atcom.caucho.util.DynamicClassLoader.loadClass(DynamicClassLoader.java:479)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:253) 本文出自:億恩科技【www.vbseamall.com】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]
|