<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>聰明的生活2 &#187; Exception</title>
	<atom:link href="http://blog.yslifes.com/archives/category/program/java/exception/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yslifes.com</link>
	<description>自己寫java程式的一些筆記</description>
	<lastBuildDate>Tue, 27 Jul 2010 02:13:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<atom:link rel='hub' href='http://blog.yslifes.com/?pushpress=hub'/>
	
<!-- Start Of Script Generated By WP-PostViews Plus -->
<script type='text/javascript' src='http://blog.yslifes.com/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
<script type="text/javascript">
/* <![CDATA[ */
jQuery.ajax({type:'GET',url:'http://blog.yslifes.com/wp-content/plugins/wp-postviews-plus/postviews_plus.php',data:'todowppvp=add&type=cat&id=84_1',cache:false,dataType:'script'});
/* ]]> */
</script>
<!-- End Of Script Generated By WP-PostViews Plus -->
	<item>
		<title>[Java]利用URLConnection檢查網站狀態</title>
		<link>http://blog.yslifes.com/archives/675</link>
		<comments>http://blog.yslifes.com/archives/675#comments</comments>
		<pubDate>Tue, 08 Jun 2010 15:26:49 +0000</pubDate>
		<dc:creator>yku</dc:creator>
				<category><![CDATA[Exception]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java基礎入門]]></category>
		<category><![CDATA[Socket]]></category>

		<guid isPermaLink="false">http://blog.yslifes.com/archives/675</guid>
		<description><![CDATA[java.net.URLConnection是一個Http Connecion物件，可以用來連接網站，並處理回傳的資訊資料，當然也可以使用socket連線來做這些事情，不過會顯的麻煩多了。 利用java.net.URLConnection可以直接取得response的Status來判斷網站是不存在、連線錯誤、無法存取，而如果需要更詳細的回傳資訊可以增加給於的Header。而如果需要取得網址的ip則可使用java.net.Inet4Address.getByName(網址名稱)。 有一點要注意的是在JDK1.4以前並有沒有setReadTimeout這個函數，所以需要自己實作一個HttpURLConnectionTimeout來操作TimeOut，可以參考Adding Socket Timeout to java.net.URLConnection這一篇。 這是範例的結果： 原始碼如下： 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 35 36 37 38 39 40 41 public class TestURLStatus &#123; [...]]]></description>
		<wfw:commentRss>http://blog.yslifes.com/archives/675/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Java]try catch finally 例外資訊處理</title>
		<link>http://blog.yslifes.com/archives/636</link>
		<comments>http://blog.yslifes.com/archives/636#comments</comments>
		<pubDate>Mon, 17 May 2010 13:30:35 +0000</pubDate>
		<dc:creator>yku</dc:creator>
				<category><![CDATA[Exception]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java基礎入門]]></category>
		<category><![CDATA[教學]]></category>

		<guid isPermaLink="false">http://blog.yslifes.com/archives/636</guid>
		<description><![CDATA[try catch是專門在處理錯誤事件的，很多程式語言都有這樣子的例外處理方法，Java也不例外，對於新入門的可能會比較少遇到這類型的問題，不過是十分重要的一環。 當程式功能越來越多、越來越大時，try catch的使用可以增加除錯(bug)的速度，try catch也可以使用其特性來製做一些技巧性的功能或判斷，而當使用者在操作期間發現了例外或錯誤，如果丟出一堆程式碼大概會讓使用者不知所為，擷取這些例外或錯誤而丟出使用者容易理解的字串，也是try catch的功能之一。 try catch 用法 try裡的敍述句有可能會丟出例外資訊 ( Exception ) ，而丟出的例外資訊 ( Exception ) 型態就可以由catch來取得，做適當的處理。finally則是在try catch完成後會執行的動作，一般都是使用在關閉或則除物件等。 ps.catch取得例外需由小範圍而後大範圍，例如java.lang.NullPointException則需寫在Exception前面，因為NullPointException所能處理的範圍比Exception還小。 try catch finally 範例 1.在進行資料庫存取時，需要取得資料庫連線，當連線有問題產生時，告知使用者資料庫連線有問題，而非丟出一堆例外訊息 ( Exception ) ，其中Connection需要寫在try catch外，在finally時才可取用。 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 [...]]]></description>
		<wfw:commentRss>http://blog.yslifes.com/archives/636/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Jsp技巧]看到錯誤碼?找到Exception位置呢?</title>
		<link>http://blog.yslifes.com/archives/634</link>
		<comments>http://blog.yslifes.com/archives/634#comments</comments>
		<pubDate>Mon, 10 May 2010 22:43:25 +0000</pubDate>
		<dc:creator>yku</dc:creator>
				<category><![CDATA[Exception]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[教學]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://blog.yslifes.com/archives/634</guid>
		<description><![CDATA[剛開始學習jsp時，看到了Exception就一個頭二個大，因為好像跟一般Java出現錯誤的表示方式不一樣，Exception的訊息寫的錯誤行數，總跟jsp裡的行數不太一樣？這樣子就不好判斷Exception產生在那裡，進而修改了！ 其實不然，在執行jsp網頁時web-server會把jsp檔先轉換成java檔，再由java檔編譯成class檔，所以要找出錯誤的地方就只需要找到java檔的所在，就可以了。 範例使用的環境是tomcat，Exception直接向網頁丟出，會看大概如下的畫面 可以看到錯誤是java.lan.NullPointException，就是有null的空指標錯誤(翻的不好，應該不能叫指標，java沒有指標) 錯誤訊息由圖上方至圖下面，一個程式一個程式向上丟出的錯誤訊息，也就是說org.apache.jsp_connect_jsp.jspService向org.apache.jasper.runtime.HttpJspBase.service丟出它的錯誤，而org.apache.jasper.runtime.HttpJspBase.service再向javax.servlet.http.HttpServlet.service丟出錯誤，以此類推。 找connect_jsp.java:136行，出NullPointException的地方在connect.jsp這隻程式的第136行，其它列的訊息，因為是系統程式，應該不是真的錯誤來源。 java的package結構，如org.apache.jsp ，也是目錄結構。 所以到tomcat目錄下的work\Catalina\localhost\0502\org\apache\jsp裡找到connect_jsp.java這程式，用記事本打開它。 ps.其中Catalina\localhost是預設的目錄，如果有更改config/server.xml內容，有可能會路徑不同。 ps.0502是網頁的子目錄，例如http://localhost:8080/0502/ 找到第136號錯誤的地方 result = stmt.executeQuery(qq);這行有NullPointException，再來只要解決這個錯誤就可以了。]]></description>
		<wfw:commentRss>http://blog.yslifes.com/archives/634/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java.sql.ResultSet absolute造成out of memory</title>
		<link>http://blog.yslifes.com/archives/360</link>
		<comments>http://blog.yslifes.com/archives/360#comments</comments>
		<pubDate>Fri, 31 Jul 2009 13:59:16 +0000</pubDate>
		<dc:creator>yku</dc:creator>
				<category><![CDATA[Exception]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[程式]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[out of memory]]></category>

		<guid isPermaLink="false">http://blog.yslifes.com/archives/360</guid>
		<description><![CDATA[java.sql.ResultSet 使用absolute方法可以移動ResultSet的指標到想要的筆數， 當 JDBC跟資料庫要資料時，會回傳一個ResultSet，但不是把所有查詢的結果均回傳至Web Server端， 而是只給前面幾筆資料，可以利用ResultSet的方法setFetchSize來設定一次回傳的筆數， (一次傳的多，等待的時間就比較長，傳的太少，要一直跟資料庫要ResultSet.next()也會比較慢) 當ResultSet向下移動碰觸或是快要碰觸到目前回傳的筆數時，會自動再跟資料庫要設定好的筆數， 而把目前筆數以上的資料全都暫存在記憶體裡。 以上是ResulSet的基本原理，當一次查詢的量夠大時，而利用absolute來移動到想要的Row時， 就有可能發生out of memory的問題， 舉個列子： 當想要取得總筆數來做分頁的totrec計算，這時利用absolute移動到最後一筆，取得getRow()來當總數， 這時資料庫會把所有的資料均吐出來給Web Server，而Web Server也會把資料暫存到記憶體裡， 而有多人一起執行這個動作時，像jsp同時有多人一起看同一頁時，則記憶體會完全來不及釋放， 試想有十萬筆*n個要求的資料暫存在記憶體裡，所以這很容易行成out of memory的Runtime Error。 解決方法其實很簡單，就是不要用absolute來取得總筆數，而是利用SQL先跟資料庫要總筆數， (select count(*) as totrec from table where 條件) 當總筆數大於零時，再跟資料庫查詢想要的資料範圍(Oracle:where field between a And b 或是MySQL: limit a,b)， 二次的請求一定比直接使用absolute佔用的記憶體少。 相關資料： Java Gossip: ResultSet 游標控制 Interface ResultSet]]></description>
		<wfw:commentRss>http://blog.yslifes.com/archives/360/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
