﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-ZengChang-随笔分类-学习笔记</title><link>http://www.blogjava.net/ZengChang/category/5920.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 08:40:22 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 08:40:22 GMT</pubDate><ttl>60</ttl><item><title>正则表达式</title><link>http://www.blogjava.net/ZengChang/archive/2006/06/03/50099.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Sat, 03 Jun 2006 01:45:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/06/03/50099.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/50099.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/06/03/50099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/50099.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/50099.html</trackback:ping><description><![CDATA[
		<table style="TABLE-LAYOUT: fixed; WORD-WRAP: break-word" height="100%" cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td valign="top">
										<a href="http://www.qdheqi.com/bbs/misc.php?action=viewratings&amp;tid=9320&amp;pid=9480" name="pid9480" alt="查看评分记录">
										</a>
										<table cellspacing="0" cellpadding="0" align="right" border="0">
												<tbody>
														<tr>
																<td>  </td>
														</tr>
												</tbody>
										</table>
										<span id="text9480">
												<span id="tpid9480">
														<span id="spid9480">如果原来没有使用过正则表达式，那么可能对这个术语和概念会不太熟悉。不过，它们并不是您想象的那么新奇。<br /><br />　　请回想一下在硬盘上是如何查找文件的。您肯定会使用 ? 和 * 字符来帮助查找您正寻找的文件。? 字符匹配文件名中的单个字符，而 * 则匹配一个或多个字符。一个如 'data?.dat' 的模式可以找到下述文件：<br /><br />　　　data1.dat<br />　　　data2.dat<br />　　　datax.dat<br />　　　dataN.dat<br /><br />　　如果使用 * 字符代替 ? 字符，则将扩大找到的文件数量。'data*.dat' 可以匹配下述所有文件名：<br /><br />　　　data.dat<br />　　　data1.dat<br />　　　data2.dat<br />　　　data12.dat<br />　　　datax.dat<br />　　　dataXYZ.dat<br /><br />　　尽管这种搜索文件的方法肯定很有用，但也十分有限。? 和 * 通配符的有限能力可以使你对正则表达式能做什么有一个概念，不过正则表达式的功能更强大，也更灵活。<br /><br />　　早期起源<br /><br />　　正则表达式的“祖先”可以一直上溯至对人类神经系统如何工作的早期研究。Warren McCulloch 和 Walter Pitts 这两位神经生理学家研究出一种数学方式来描述这些神经网络。<br /><br />　　1956 年, 一位叫 Stephen Kleene 的数学家在 McCulloch 和 Pitts 早期工作的基础上，发表了一篇标题为“神经网事件的表示法”的论文，引入了正则表达式的概念。正则表达式就是用来描述他称为“正则集的代数”的表达式，因此采用“正则表达式”这个术语。<br /><br />　　随后，发现可以将这一工作应用于使用 Ken Thompson 的计算搜索算法的一些早期研究，Ken Thompson 是 Unix 的主要发明人。正则表达式的第一个实用应用程序就是 Unix 中的 qed 编辑器。<br /><br />　　如他们所说，剩下的就是众所周知的历史了。从那时起直至现在正则表达式都是基于文本的编辑器和搜索工具中的一个重要部分。<br /><br />　　使用正则表达式<br /><br />　　在典型的搜索和替换操作中，必须提供要查找的确切文字。这种技术对于静态文本中的简单搜索和替换任务可能足够了，但是由于它缺乏灵活性，因此在搜索动态文本时就有困难了，甚至是不可能的。<br /><br />　　使用正则表达式，就可以：<br /><br />　　·测试字符串的某个模式。例如，可以对一个输入字符串进行测试，看在该字符串是否存在一个电话号码模式或一个信用卡号码模式。这称为数据有效性验证。<br /><br />　　·替换文本。可以在文档中使用一个正则表达式来标识特定文字，然后可以全部将其删除，或者替换为别的文字。<br /><br />　　·根据模式匹配从字符串中提取一个子字符串。可以用来在文本或输入字段中查找特定文字。<br /><br />　　例如，如果需要搜索整个 web 站点来删除某些过时的材料并替换某些HTML 格式化标记，则可以使用正则表达式对每个文件进行测试，看在该文件中是否存在所要查找的材料或 HTML 格式化标记。用这个方法，就可以将受影响的文件范围缩小到包含要删除或更改的材料的那些文件。然后可以使用正则表达式来删除过时的材料，最后，可以再次使用正则表达式来查找并替换那些需要替换的标记。<br /><br />　　另一个说明正则表达式非常有用的示例是一种其字符串处理能力还不为人所知的语言。 VBScript 是 Visual Basic 的一个子集，具有丰富的字符串处理功能。与 C 类似的 Jscript 则没有这一能力。正则表达式给 JScript 的字符串处理能力带来了明显改善。不过，可能还是在 VBScript 中使用正则表达式的效率更高，它允许在单个表达式中执行多个字符串操作。<br /><br />　　正则表达式语法<br /><br />　　一个正则表达式就是由普通字符（例如字符 a 到 z）以及特殊字符（称为元字符）组成的文字模式。该模式描述在查找文字主体时待匹配的一个或多个字符串。正则表达式作为一个模板，将某个字符模式与所搜索的字符串进行匹配。<br /><br />　　这里有一些可能会遇到的正则表达式示例：<br /><br />JScript         VBScript         匹配<br />/^\[ \t]*$/         "^\[ \t]*$"         匹配一个空白行。<br />/\d{2}-\d{5}/         "\d{2}-\d{5}"         验证一个ID 号码是否由一个2位数字，一个连字符以及一个5位数字组成。<br />/＜(.*)＞.*＜\/\1＞/         "＜(.*)＞.*＜\/\1＞"         匹配一个 HTML 标记。<br /><br />　　下表是元字符及其在正则表达式上下文中的行为的一个完整列表：<br /><br />字符         描述<br />\         将下一个字符标记为一个特殊字符、或一个原义字符、或一个 向后引用、或一个八进制转义符。例如，'n' 匹配字符 "n"。'\n' 匹配一个换行符。序列 '\\' 匹配 "\" 而 "\(" 则匹配 "("。<br />^         匹配输入字符串的开始位置。如果设置了 RegExp 对象的 Multiline 属性，^ 也匹配 '\n' 或 '\r' 之后的位置。<br />$         匹配输入字符串的结束位置。如果设置了RegExp 对象的 Multiline 属性，$ 也匹配 '\n' 或 '\r' 之前的位置。<br />*         匹配前面的子表达式零次或多次。例如，zo* 能匹配 "z" 以及 "zoo"。* 等价于{0,}。<br />+         匹配前面的子表达式一次或多次。例如，'zo+' 能匹配 "zo" 以及 "zoo"，但不能匹配 "z"。+ 等价于 {1,}。<br />?         匹配前面的子表达式零次或一次。例如，"do(es)?" 可以匹配 "do" 或 "does" 中的"do" 。? 等价于 {0,1}。<br />{n}         n 是一个非负整数。匹配确定的 n 次。例如，'o{2}' 不能匹配 "Bob" 中的 'o'，但是能匹配 "food" 中的两个 o。<br />{n,}         n 是一个非负整数。至少匹配n 次。例如，'o{2,}' 不能匹配 "Bob" 中的 'o'，但能匹配 "foooood" 中的所有 o。'o{1,}' 等价于 'o+'。'o{0,}' 则等价于 'o*'。<br />{n,m}         m 和 n 均为非负整数，其中n ＜= m。最少匹配 n 次且最多匹配 m 次。例如，"o{1,3}" 将匹配 "fooooood" 中的前三个 o。'o{0,1}' 等价于 'o?'。请注意在逗号和两个数之间不能有空格。<br />?         当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时，匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串，而默认的贪婪模式则尽可能多的匹配所搜索的字符串。例如，对于字符串 "oooo"，'o+?' 将匹配单个 "o"，而 'o+' 将匹配所有 'o'。<br />.         匹配除 "\n" 之外的任何单个字符。要匹配包括 '\n' 在内的任何字符，请使用象 '[.\n]' 的模式。<br />(pattern)         匹配 pattern 并获取这一匹配。所获取的匹配可以从产生的 Matches 集合得到，在VBScript 中使用 SubMatches 集合，在JScript 中则使用 $0…$9 属性。要匹配圆括号字符，请使用 '\(' 或 '\)'。<br />(?:pattern)         匹配 pattern 但不获取匹配结果，也就是说这是一个非获取匹配，不进行存储供以后使用。这在使用 "或" 字符 (|) 来组合一个模式的各个部分是很有用。例如， 'industr(?:y|ies) 就是一个比 'industry|industries' 更简略的表达式。<br />(?=pattern)         正向预查，在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配，也就是说，该匹配不需要获取供以后使用。例如，'Windows (?=95|98|NT|2000)' 能匹配 "Windows 2000" 中的 "Windows" ，但不能匹配 "Windows 3.1" 中的 "Windows"。预查不消耗字符，也就是说，在一个匹配发生后，在最后一次匹配之后立即开始下一次匹配的搜索，而不是从包含预查的字符之后开始。<br />(?!pattern)         负向预查，在任何不匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配，也就是说，该匹配不需要获取供以后使用。例如'Windows (?!95|98|NT|2000)' 能匹配 "Windows 3.1" 中的 "Windows"，但不能匹配 "Windows 2000" 中的 "Windows"。预查不消耗字符，也就是说，在一个匹配发生后，在最后一次匹配之后立即开始下一次匹配的搜索，而不是从包含预查的字符之后开始<br />x|y         匹配 x 或 y。例如，'z|food' 能匹配 "z" 或 "food"。'(z|f)ood' 则匹配 "zood" 或 "food"。<br />[xyz]         字符集合。匹配所包含的任意一个字符。例如， '[abc]' 可以匹配 "plain" 中的 'a'。<br />[^xyz]         负值字符集合。匹配未包含的任意字符。例如， '[^abc]' 可以匹配 "plain" 中的'p'。<br />[a-z]         字符范围。匹配指定范围内的任意字符。例如，'[a-z]' 可以匹配 'a' 到 'z' 范围内的任意小写字母字符。<br />[^a-z]         负值字符范围。匹配任何不在指定范围内的任意字符。例如，'[^a-z]' 可以匹配任何不在 'a' 到 'z' 范围内的任意字符。<br />\b         匹配一个单词边界，也就是指单词和空格间的位置。例如， 'er\b' 可以匹配"never" 中的 'er'，但不能匹配 "verb" 中的 'er'。<br />\B         匹配非单词边界。'er\B' 能匹配 "verb" 中的 'er'，但不能匹配 "never" 中的 'er'。<br />\cx         匹配由 x 指明的控制字符。例如， \cM 匹配一个 Control-M 或回车符。x 的值必须为 A-Z 或 a-z 之一。否则，将 c 视为一个原义的 'c' 字符。<br />\d         匹配一个数字字符。等价于 [0-9]。<br />\D         匹配一个非数字字符。等价于 [^0-9]。<br />\f         匹配一个换页符。等价于 \x0c 和 \cL。<br />\n         匹配一个换行符。等价于 \x0a 和 \cJ。<br />\r         匹配一个回车符。等价于 \x0d 和 \cM。<br />\s         匹配任何空白字符，包括空格、制表符、换页符等等。等价于 [ \f\n\r\t\v]。<br />\S         匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。<br />\t         匹配一个制表符。等价于 \x09 和 \cI。<br />\v         匹配一个垂直制表符。等价于 \x0b 和 \cK。<br />\w         匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]'。<br />\W         匹配任何非单词字符。等价于 '[^A-Za-z0-9_]'。<br />\xn         匹配 n，其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。例如，'\x41' 匹配 "A"。'\x041' 则等价于 '\x04' &amp; "1"。正则表达式中可以使用 ASCII 编码。.<br />\num         匹配 num，其中 num 是一个正整数。对所获取的匹配的引用。例如，'(.)\1' 匹配两个连续的相同字符。<br />\n         标识一个八进制转义值或一个向后引用。如果 \n 之前至少 n 个获取的子表达式，则 n 为向后引用。否则，如果 n 为八进制数字 (0-7)，则 n 为一个八进制转义值。<br />\nm         标识一个八进制转义值或一个向后引用。如果 \nm 之前至少有 nm 个获得子表达式，则 nm 为向后引用。如果 \nm 之前至少有 n 个获取，则 n 为一个后跟文字 m 的向后引用。如果前面的条件都不满足，若 n 和 m 均为八进制数字 (0-7)，则 \nm 将匹配八进制转义值 nm。<br />\nml         如果 n 为八进制数字 (0-3)，且 m 和 l 均为八进制数字 (0-7)，则匹配八进制转义值 nml。<br />\un         匹配 n，其中 n 是一个用四个十六进制数字表示的 Unicode 字符。例如， \u00A9 匹配版权符号 (©)。</span>
												</span>
										</span>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/ZengChang/aggbug/50099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-06-03 09:45 <a href="http://www.blogjava.net/ZengChang/archive/2006/06/03/50099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在页面上显示HTML代码的JAVA SCRIPT</title><link>http://www.blogjava.net/ZengChang/archive/2006/06/01/49703.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Thu, 01 Jun 2006 09:00:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/06/01/49703.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49703.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/06/01/49703.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49703.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49703.html</trackback:ping><description><![CDATA[&lt;script defer&gt;<br />function _show(str){<br /> var w=window.open('','');<br /> var d=w.document;<br /> d.open();<br /> str=str.replace(/=(?!")(.*?)(?!")( |&gt;)/g,"=\"$1\"$2");<br /> str=str.replace(/(&lt;)(.*?)(&gt;)/g,"&lt;span style='color:red;'&gt;&amp;lt;$2&amp;gt;&lt;/span&gt;&lt;br /&gt;");<br /> str=str.replace(/\r/g,"&lt;br /&gt;\n");<br /> d.write(str);<br /> }<br />&lt;/script&gt;<br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;form&gt;<br />&lt;input type="button" value="SHOW" onClick="_show(document.documentElement.innerHTML)" /&gt;<br />&lt;/form&gt;<br />&lt;/body&gt;<br />&lt;/html&gt; <br /><br />中间用了正则表达式<img src ="http://www.blogjava.net/ZengChang/aggbug/49703.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-06-01 17:00 <a href="http://www.blogjava.net/ZengChang/archive/2006/06/01/49703.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL 存储过程分页代码</title><link>http://www.blogjava.net/ZengChang/archive/2006/06/01/49557.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Thu, 01 Jun 2006 06:07:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/06/01/49557.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49557.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/06/01/49557.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49557.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49557.html</trackback:ping><description><![CDATA[
		<p>CREATE procedure pagination12222<br />(@pagesize int, --页面大小，如每页存储20条记录<br />@pageindex int --当前页码<br />)<br />as</p>
		<p>set nocount on</p>
		<p>begin<br />declare @indextable table(id int identity(1,1),nid int) --定义表变量<br />declare @PageLowerBound int --定义此页的底码<br />declare @PageUpperBound int --定义此页的顶码<br />set @PageLowerBound=(@pageindex-1)*@pagesize<br />set @PageUpperBound=@PageLowerBound+@pagesize<br />set rowcount @PageUpperBound<br />insert into @indextable(nid) select hhh from BEFORE_A <br />order by HHH desc<br />select O.hhh,O.lblh,O.lblm,O.dwmc,O.yljy from BEFORE_A O,@indextable t <br />           where O.hhh=t.nid and t.id&gt;@PageLowerBound <br />                        and t.id&lt;<a href="mailto:=@PageUpperBound">=@PageUpperBound</a> order by t.id<br />end</p>
		<p>set nocount off</p>
		<p>GO <br /></p>
<img src ="http://www.blogjava.net/ZengChang/aggbug/49557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-06-01 14:07 <a href="http://www.blogjava.net/ZengChang/archive/2006/06/01/49557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>优化JDBC编程</title><link>http://www.blogjava.net/ZengChang/archive/2006/06/01/49399.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Thu, 01 Jun 2006 01:09:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/06/01/49399.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49399.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/06/01/49399.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49399.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49399.html</trackback:ping><description><![CDATA[
		<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">
				<span style="FONT-SIZE: 15pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 9.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">优化</span>
				<span lang="EN-US" style="FONT-SIZE: 15pt; mso-bidi-font-size: 9.5pt; mso-bidi-font-family: Tahoma">JDBC</span>
				<span style="FONT-SIZE: 15pt; FONT-FAMILY: 宋体; mso-bidi-font-size: 9.5pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">编程</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />
				</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这是我根据</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">MS SQL SERVER 2000 JDBC DRIVER HELP</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，并参考其它资料整理而成。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">ms</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">的这个帮助文件实在有失大家风范，示例代码很</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">.....</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">有兴趣者可以去下载</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">http://download.microsoft.com/download/SQLSVR2000/jdbc/2000/NT45XP/EN-US/setup.exe</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">。由于本人水平有限，文中不当之处请大家批评指正。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />1.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">尽量减少对数据库元数据方法的使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">同样是产生一个</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">ResultSet</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DatabaseMetaData </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象的方法比其它</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JDBC</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法相对要慢，因此平繁使用该方法会降低系统的性能。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">  </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">在程序中应当对产生的结果集信息进行高速缓存，比如将</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getTypeInfo()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">返回的结果集存入</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Vector</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">或</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Hashtable</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">中，这样可大大提高程序的效率。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />2.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">应避免的方法调用模式</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">在方法调用时应当尽量避免传入</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">null</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">做为参数，虽然有时能执行成功，但这对</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DB Server</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">负担很重。其实在很多情况下所需的参数是已知的。比如：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    //</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这里略去了捕获违例代码（下同）。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    DatabaseMetaData md=...;<br />    ResultSet rs=md.getTables(null,null,"authors",null);//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">取得</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">MS SQL SERVER pubs</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">数据库中</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">authors</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">表的信息</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">.<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">应当写成：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />       ResultSet rs=md.getTables("northwind","dbo","authors",new String[]{"TABLE"});<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这样使程序更有效可靠。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />3.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">使用哑查询语句来取得表的相关特征信息</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">一个哑查询语句（</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Dummy Query</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，译为哑查询不知是否恰当，愿与大家探讨）不会产生有记录的结果集，比如：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">select * from tableName where 1=0</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，因为条件永不成立，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DB Server </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">不会执行这条语句。因此，在不需产生记录行的情况下，哑查询能极大地提高程序的执行效率。比如我们要了解一个表的有关列信息时，上面的语句比</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">select * from tableName</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这个语句要高效得多，后者数据库服务器要检索所有的行并返回一个记录集，而前者不需要。针对这一问题，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JDBC</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">可以有以下两种方法：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    case 1:</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getColumns()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        //getColumns()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">是</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DatabaseMetaData</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">的一个方法，其有关信息请查阅</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JDK1.3</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">文档</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        ResultSet rs=md.getColumns("pubs","dbo","authors",...);//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">返回一个有记录的结果集</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        while(rs.next())//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">通过滚动结果集取得列名</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />            System.out.println(rs.getString(4));<br />    case 2:</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getMetaData()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        Statement stmt=conn.createStatement();<br />        //</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">数据库服务器永远不会执行这条查询语句</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        ResultSet rs=stmt.executeQuery("select * from authors where 1=0");<br />        ResultSetMetaData rsmd=rs.getMetaData();<br />        int colCount=rsmd.getColumnCount();//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">取得列数</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />        for(int col=1;col&lt;=colCount;col++)<br />            System.out.println(rsmd.getColumnName(col));<br />        //!</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这里列的顺序是</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">select</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">后列出现的顺序，并不一定与表中列顺序对应</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">通过以上的分析，第二种方法应是我们的选择。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />4.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">关于存储过程的调用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">由于所有的</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JDBC</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">驱动总是将</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">SQL</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">语句作为字符串发送到数据库服务器，数据库服务器经过语法分析、参数类型验证，然后将参数转换成正确的数据类型再去执行。比如有这么一个存储过程：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      CallableStatement cstmt=conn.prepareCall("{call getCustomerName(123)}");<br />      //</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">获得指定</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">id</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">的客户的名字，输入参数，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">id</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">是个正整数</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      ResultSet rs=cstmt.executeQuery();<br />      </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">在这里我们认为</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">123</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">是一个正整数，但实际</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">"call getCustomerName(123)"</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">作为字符串整个被发送到数据库服务器端，数据库服务器经过分析，离析出</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">"123"</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">将其转换为整数型值再做为参数送给存储过程执行。很明显，这样效率极低，因为我们把已知的东西仍要服务器去判断，这无疑额外加重了服务器的负担。做为优化也是我们常见的存储过程的调用方法应是：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      CallableStatement cstmt=conn.prepareCall("call getCustomerName(?)");<br />      cstmt.setLong(1,123);//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">将值和类型信息编码后发送</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      ResultSet rs=cstmt.executeQuery();<br />      //do something<br />5.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">正确使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Statement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">PreparedStatement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象及其</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">execute</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    Statement </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象是为仅执行一次的查询语句优化而设计的，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">PreparedStatement </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象是为两次或更多次执行同一查询语句而设计的。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">PreparedStatement </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象第一次执行一个准备好的查询要花一定的代价，然而它带来的好处是为以后的查询加快了速度；因为</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">SQL</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">语句已经进行编译并放入高速缓存，你可以一直重复使用；想要改变查询条件获得不同的结果集只需用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">setXXX</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法改变主机变量（</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">?</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">）的值就行了。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">由于</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">PreparedStatement </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">及</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma"> CallableStatement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">都是</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Statement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">的子类，所以它们都有</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">execute(String sql),executeQuery(String sql),executeUpdate(String sql),executeBatch()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      execute(String sql)</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法返回一个</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">boolean</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">值，它执行任意复杂的</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">sql</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">语句，可以产生多个结果集。如果有结果产生返回</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma"> true</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，如果没有结果集产生或仅是一个更新记数则返回</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma"> false</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">。它产生的结果集可以通过</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getResultSet()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getMoreResults()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">获得，更新记数可通过</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">getUpdateCount()</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">获得。显然</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">execute(String sql)</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法的使用要复杂一些，因此如果只是简单的查询或更新操作请使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">executeQuery(String sql)</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">executeUpdate(String sql)</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">方法。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">executeUpdate(String sql)</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">能执行</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">INSERT</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">UPDATE</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DELETE</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">语句，及</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DDL</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">DML</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">命令（此时返回值为</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">0</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">）。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">如果需要进行更多的更新操作，只需将这些更新命令打包后一起提交给数据库，数据库一次处理所有的请求，这比逐条提交要高效得多。例如：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      //</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">保存当前提交模式</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      boolean commitState=conn.getAutoCommit();<br />      // </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">关闭自动提交模式</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      conn.setAutoCommit(false);<br />      Statement stmt = conn.createStatement();<br />      //</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">逐条加入</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      stmt.addBatch("INSERT INTO employees VALUES (1000, 'Joe Jones')");<br />      stmt.addBatch("INSERT INTO departments VALUES (260, 'Shoe')");<br />      stmt.addBatch("INSERT INTO emp_dept VALUES (1000, 260)");<br />      // </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">一次提交</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      int[] updateCounts = stmt.executeBatch();<br />      conn.commit();//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">使更新生效</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      conn.setAutoCommit(commitState);//</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">恢复原来的提交模式</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />      PreparedStatement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">CallalbeStatement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">对象的使用基本与</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Statement</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">一样，请参阅</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JDBC2.1API</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />6.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">正确的使用游标</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    JDBC2.1</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">核心</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">API</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">提供三种结果集类型：</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">forward-only, scroll-insensitive</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">和</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">scroll-sensitive</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    forward-only</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">：仅向前型。如果你仅需要前向顺序滚动结果集中的所有行，仅向前游标能提供极高的性能；然而它不能从第一行上直接滚动到最后一行，也不能从最后一行滚到第一行。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    scroll-insensitive</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">：滚动不敏感型。对于要求较高处理级别的应用来说，滚动不敏感型结果集是一个理想的选择，它支持向前和向后的记录集滚动。滚动不敏感型结果集的第一次请求是从数据库服务端取得所有满足条件的行，然后将它存储在客户端，也就是说是一个包含数据的客户端静态视图；虽然以后的操作比较快，但数据库服务器处理第一次的请求非常慢，尤其是当返回的数据量比较大时。因此，如果返回的只是一行记录我们就不应使用这种游标，使用仅向前就满足要求了；相反，如果返回的记录非常多，也不推荐使用这种游标，因为这些数据都存放在内存里，大量的数据将很快使内存耗尽。有些滚动不敏感游标的实现是将数据缓存到数据库服务器的一个临时表中，以免占用过多的内存资源。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    scroll-sensitive</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">：滚动敏感型，有时也叫键集驱动游标。它是在你的数据库上对满足条件的记录行做了一个标识，好像行的主键，当你滚动结果集的时候，只有有标识的数据才会返回。由于每次的请求都要产生一次网络连接，因此速度是很慢的。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />7.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">只返回需要的行或列</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">听了上周六范生对</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">Oracle</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">核心的剖析，我算是搞清楚了对表的查询或更新，数据库低层操作其实是对磁盘文件的</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">read or write</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，而</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">I/O</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">操作数据量越大耗时越多，软盘的读写速度大家是有目共睹的。为了避免不必要的数据传输，请小心使用</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">select * from ...</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">这样的语句，如果只需要一列就没必要返回所有的列，特别是当你不需要的列中含有大数据类型（如</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">BINARY</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">BLOB</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">，</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">CLOB</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">）或者说数据量较大时，会影响系统性能。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />8.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">使用连接池</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">连接池对数据库访问性能的提高是非常显著地，因为创建和销毁一个连接的代价都非常昂贵。连接池实现了数据库连接的共享，一个连接对象可以被多个用户多次重复使用。由容器管理的连接池就像是一个租赁公司，谁要使用就租给他一个，用完后还给我，下次要用接着出租，这样就免去了每次请求都要造个新的，而用完后又把它扔了。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />    </span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">关于连接池技术较为复杂，不过你也完全可以写自己的连接池对象，如果你看了《</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JAVA2</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">高级编程》。</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />
						<br />[</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">参考资料</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">]<br />  1.MS SQL SERVER 2000 JDBC DRIVER HELP<br />  2.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">《</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JAVA2</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">高级编程》</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />  3.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">《</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JAVA2</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">核心技术</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">II</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">》</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />  4.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">《</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">J2EE</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">构建企业系统专家级解决方案》</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />  5.</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">《</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">JSP</span>
				<span style="FONT-SIZE: 9.5pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: Tahoma">高级编程》</span>
				<span lang="EN-US" style="FONT-SIZE: 9.5pt; mso-bidi-font-family: Tahoma">
						<br />  6.SUN JDBC2.1 API</span>
		</p>
<img src ="http://www.blogjava.net/ZengChang/aggbug/49399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-06-01 09:09 <a href="http://www.blogjava.net/ZengChang/archive/2006/06/01/49399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java如何调用DOS命令,</title><link>http://www.blogjava.net/ZengChang/archive/2006/05/31/49287.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Wed, 31 May 2006 08:27:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/05/31/49287.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49287.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/05/31/49287.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49287.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49287.html</trackback:ping><description><![CDATA[
		<p>/*<br /> * Created on 2006-5-27<br /> *<br /> * TODO To change the template for this generated file go to<br /> * Window - Preferences - Java - Code Style - Code Templates<br /> */<br />package com.zeng;</p>
		<p>/**<br /> * @author Administrator<br /> *<br /> * TODO To change the template for this generated type comment go to<br /> * Window - Preferences - Java - Code Style - Code Templates<br /> */<br /><br />public class TestCmd { <br />  public static void main(String[] args) throws Exception { <br />   try{<br />    String cmd = "cmd.exe /c \"mkdir d:\\temp\\005\""; <br />                      //可去掉一组引号"cmd.exe /c mkdir d:\\temp\\005"; <br />                     //cmd.exe /c为固定格式,mkdir d:\\temp\\005是DOS命令,<br />                     //此命令在D盘创建一个目录d:\temp\005<br />       Runtime.getRuntime().exec(cmd); <br />       }catch(Exception e){<br />    e.printStackTrace();<br />    } <br />   } <br /> }</p>
<img src ="http://www.blogjava.net/ZengChang/aggbug/49287.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-05-31 16:27 <a href="http://www.blogjava.net/ZengChang/archive/2006/05/31/49287.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSP生成彩色验证码</title><link>http://www.blogjava.net/ZengChang/archive/2006/05/31/49286.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Wed, 31 May 2006 08:20:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/05/31/49286.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49286.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/05/31/49286.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49286.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49286.html</trackback:ping><description><![CDATA[
		<p>&lt;%@ page contentType="image/jpeg" import="java.awt.*,<br />java.awt.image.*,java.util.*,javax.imageio.*" %&gt;<br />&lt;%!<br />Color getRandColor(int fc,int bc){//给定范围获得随机颜色<br />        Random random = new Random();<br />        if(fc&gt;255) fc=255;<br />        if(bc&gt;255) bc=255;<br />        int r=fc+random.nextInt(bc-fc);<br />        int g=fc+random.nextInt(bc-fc);<br />        int b=fc+random.nextInt(bc-fc);<br />        return new Color(r,g,b);<br />        }<br />%&gt;<br />&lt;%<br />//设置页面不缓存<br />response.setHeader("Pragma","No-cache");<br />response.setHeader("Cache-Control","no-cache");<br />response.setDateHeader("Expires", 0);</p>
		<p> </p>
		<p>// 在内存中创建图象<br />int width=60, height=20;<br />BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);</p>
		<p> </p>
		<p>// 获取图形上下文<br />Graphics g = image.getGraphics();</p>
		<p> </p>
		<p>//生成随机类<br />Random random = new Random();</p>
		<p> </p>
		<p>// 设定背景色<br />g.setColor(getRandColor(200,250));<br />g.fillRect(0, 0, width, height);</p>
		<p> </p>
		<p>//设定字体<br />g.setFont(new Font("Times New Roman",Font.PLAIN,18));</p>
		<p> </p>
		<p>//画边框<br />//g.setColor(new Color());<br />//g.drawRect(0,0,width-1,height-1);</p>
		<p> </p>
		<p>// 随机产生155条干扰线，使图象中的认证码不易被其它程序探测到<br />g.setColor(getRandColor(160,200));<br />for (int i=0;i&lt;155;i++)<br />{<br /> int x = random.nextInt(width);<br /> int y = random.nextInt(height);<br />        int xl = random.nextInt(12);<br />        int yl = random.nextInt(12);<br /> g.drawLine(x,y,x+xl,y+yl);<br />}</p>
		<p> </p>
		<p>// 取随机产生的认证码(4位数字)<br />String sRand="";<br />for (int i=0;i&lt;4;i++){<br />    String rand=String.valueOf(random.nextInt(10));<br />    sRand+=rand;<br />    // 将认证码显示到图象中<br />    g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));<br />//调用函数出来的颜色相同，可能是因为种子太接近，所以只能直接生成<br />    g.drawString(rand,13*i+6,16);<br />}</p>
		<p> </p>
		<p>// 将认证码存入SESSION<br />session.setAttribute("rand",sRand);</p>
		<p> </p>
		<p>// 图象生效<br />g.dispose();</p>
		<p> </p>
		<p>// 输出图象到页面<br />ImageIO.write(image, "JPEG", response.getOutputStream());<br />%&gt;</p>
<img src ="http://www.blogjava.net/ZengChang/aggbug/49286.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-05-31 16:20 <a href="http://www.blogjava.net/ZengChang/archive/2006/05/31/49286.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用servlet将JSP转换为静态页面</title><link>http://www.blogjava.net/ZengChang/archive/2006/05/31/49282.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Wed, 31 May 2006 08:18:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2006/05/31/49282.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/49282.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2006/05/31/49282.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/49282.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/49282.html</trackback:ping><description><![CDATA[
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">import java.io.ByteArrayOutputStream;<br />import java.io.FileOutputStream;<br />import java.io.IOException;<br />import java.io.OutputStreamWriter;<br />import java.io.PrintWriter;<br /><br />import javax.servlet.RequestDispatcher;<br />import javax.servlet.ServletContext;<br />import javax.servlet.ServletException;<br />import javax.servlet.ServletOutputStream;<br />import javax.servlet.http.HttpServlet;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />import javax.servlet.http.HttpServletResponseWrapper;<br /><br />public class toHtml extends HttpServlet<br />{<br /><br />    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException<br />    {<br />    String url="";<br />    String name="";<br />    <br />        ServletContext sc = getServletContext();<br />        <br />        String file_name=request.getParameter("file_name");//</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">你要访问的</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">jsp</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">,</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">index.jsp<br />  //</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">则你访问这个</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">servlet</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">时加参数</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">.</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">http://localhost/toHtml?file_name=index<br /><br />        url = "/"+file_name+".jsp";//</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">这是你要生成</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">HTML</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">jsp</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">,</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
				<br />                                   //http://localhost/index.jsp</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">的执行结果</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">.<br /><br />        name="/home/resin/resin-<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /?><st1:chsdate year="1899" month="12" day="30" islunardate="False" isrocdate="False" w:st="on">2.1.6</st1:chsdate>/doc/"+file_name+".htm";//</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">这是生成的</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">html</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">文件名</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">,</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">如</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">index.htm.<br />                <br />        RequestDispatcher rd = sc.getRequestDispatcher(url);<br />        <br />        final ByteArrayOutputStream os = new ByteArrayOutputStream();<br />        <br />        final ServletOutputStream stream = new ServletOutputStream()<br />        {<br />            public void write(byte[] data, int offset, int length)<br />            {<br />                os.write(data, offset, length);<br />            }<br /><br />            public void write(int b) throws IOException<br />            {<br />                os.write(b);<br />            }<br />        };<br />        <br />        final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));<br />        <br />        HttpServletResponse rep = new HttpServletResponseWrapper(response)<br />        {<br />            public ServletOutputStream getOutputStream()<br />            {<br />                return stream;<br />            }<br />            <br />            public PrintWriter getWriter()<br />            {<br />                return pw;<br />            }<br />        };<br />        rd.include(request, rep);<br />        pw.flush();       <br />        FileOutputStream fos = new FileOutputStream(name); //</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">把</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">jsp</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">输出的内容写到</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">xxx.htm<br />        os.writeTo(fos);<br />        fos.close();<br />        PrintWriter out=response.getWriter();<br />        out.print("&lt;p align=center&gt;&lt;font size=3 color=red&gt;</span>
		<span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">首页已经成功生成！</span>
		<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-fareast-font-family: 宋体; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">Andrew&lt;/font&gt;&lt;/p&gt;");<br />    }<br />}<br style="mso-special-character: line-break" /><br style="mso-special-character: line-break" /></span>
<img src ="http://www.blogjava.net/ZengChang/aggbug/49282.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2006-05-31 16:18 <a href="http://www.blogjava.net/ZengChang/archive/2006/05/31/49282.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MD5算法的JAVA_BEAN</title><link>http://www.blogjava.net/ZengChang/archive/2005/12/31/26192.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Sat, 31 Dec 2005 08:28:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2005/12/31/26192.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/26192.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2005/12/31/26192.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/26192.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/26192.html</trackback:ping><description><![CDATA[<P>package org.waityou.news.util;</P>
<P>import java.lang.reflect.*;</P>
<P>/*******************************************************************************<BR>&nbsp;* md5 类实现了RSA Data Security, Inc.在提交给IETF 的RFC1321中的MD5 message-digest 算法。<BR>&nbsp;******************************************************************************/</P>
<P>public class MD5 {<BR>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 下面这些S11-S44实际上是一个4*4的矩阵，在原始的C实现中是用#define 实现的， 这里把它们实现成为static<BR>&nbsp;&nbsp;&nbsp;&nbsp; * final是表示了只读，切能在同一个进程空间内的多个 Instance间共享<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; static final int S11 = 7;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S12 = 12;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S13 = 17;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S14 = 22;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S21 = 5;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S22 = 9;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S23 = 14;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S24 = 20;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S31 = 4;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S32 = 11;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S33 = 16;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S34 = 23;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S41 = 6;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S42 = 10;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S43 = 15;</P>
<P>&nbsp;&nbsp;&nbsp; static final int S44 = 21;</P>
<P>&nbsp;&nbsp;&nbsp; static final byte[] PADDING = { -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, 0, 0, 0, 0, 0, 0 };</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 下面的三个成员是MD5计算过程中用到的3个核心数据，在原始的C实现中 被定义到MD5_CTX结构中<BR>&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private long[] state = new long[4]; // state (ABCD)</P>
<P>&nbsp;&nbsp;&nbsp; private long[] count = new long[2]; // number of bits, modulo 2^64 (lsb</P>
<P>&nbsp;&nbsp;&nbsp; // first)</P>
<P>&nbsp;&nbsp;&nbsp; private byte[] buffer = new byte[64]; // input buffer</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * digestHexStr是MD5的唯一一个公共成员，是最新一次计算结果的 16进制ASCII表示.<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; public String digestHexStr;</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * digest,是最新一次计算结果的2进制内部表示，表示128bit的MD5值.<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private byte[] digest = new byte[16];</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * getMD5ofStr是类MD5最主要的公共方法，入口参数是你想要进行MD5变换的字符串<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 返回的是变换完的结果，这个结果是从公共成员digestHexStr取得的．<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; public String getMD5ofStr(String inbuf) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Init();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Update(inbuf.getBytes(), inbuf.length());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Final();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; digestHexStr = "";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 16; i++) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; digestHexStr += byteHEX(digest[i]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return digestHexStr;</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; // 这是MD5这个类的标准构造函数，JavaBean要求有一个public的并且没有参数的构造函数<BR>&nbsp;&nbsp;&nbsp; public MD5() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Init();</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /* md5Init是一个初始化函数，初始化核心变量，装入标准的幻数 */<BR>&nbsp;&nbsp;&nbsp; private void md5Init() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count[0] = 0L;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count[1] = 0L;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Load magic initialization constants.</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[0] = 0x67452301L;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[1] = 0xefcdab89L;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[2] = 0x98badcfeL;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[3] = 0x10325476L;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * F, G, H ,I 是4个基本的MD5函数，在原始的MD5的C实现中，由于它们是<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 简单的位运算，可能出于效率的考虑把它们实现成了宏，在java中，我们把它们 实现成了private方法，名字保持了原来C中的。<BR>&nbsp;&nbsp;&nbsp;&nbsp; */</P>
<P>&nbsp;&nbsp;&nbsp; private long F(long x, long y, long z) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (x &amp; y) | ((~x) &amp; z);</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long G(long x, long y, long z) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (x &amp; z) | (y &amp; (~z));</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long H(long x, long y, long z) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return x ^ y ^ z;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long I(long x, long y, long z) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return y ^ (x | (~z));<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * FF,GG,HH和II将调用F,G,H,I进行近一步变换 FF, GG, HH, and II transformations for<BR>&nbsp;&nbsp;&nbsp;&nbsp; * rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent<BR>&nbsp;&nbsp;&nbsp;&nbsp; * recomputation.<BR>&nbsp;&nbsp;&nbsp;&nbsp; */</P>
<P>&nbsp;&nbsp;&nbsp; private long FF(long a, long b, long c, long d, long x, long s, long ac) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += F(b, c, d) + x + ac;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = ((int) a &lt;&lt; s) | ((int) a &gt;&gt;&gt; (32 - s));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += b;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long GG(long a, long b, long c, long d, long x, long s, long ac) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += G(b, c, d) + x + ac;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = ((int) a &lt;&lt; s) | ((int) a &gt;&gt;&gt; (32 - s));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += b;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long HH(long a, long b, long c, long d, long x, long s, long ac) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += H(b, c, d) + x + ac;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = ((int) a &lt;&lt; s) | ((int) a &gt;&gt;&gt; (32 - s));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += b;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; private long II(long a, long b, long c, long d, long x, long s, long ac) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += I(b, c, d) + x + ac;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = ((int) a &lt;&lt; s) | ((int) a &gt;&gt;&gt; (32 - s));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a += b;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * md5Update是MD5的主计算过程，inbuf是要变换的字节串，inputlen是长度，这个<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 函数由getMD5ofStr调用，调用之前需要调用md5init，因此把它设计成private的<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private void md5Update(byte[] inbuf, int inputLen) {</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, index, partLen;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] block = new byte[64];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = (int) (count[0] &gt;&gt;&gt; 3) &amp; 0x3F;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // /* Update number of bits */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ((count[0] += (inputLen &lt;&lt; 3)) &lt; (inputLen &lt;&lt; 3))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count[1]++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; count[1] += (inputLen &gt;&gt;&gt; 29);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; partLen = 64 - index;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Transform as many times as possible.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (inputLen &gt;= partLen) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Memcpy(buffer, inbuf, index, 0, partLen);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Transform(buffer);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = partLen; i + 63 &lt; inputLen; i += 64) {</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Memcpy(block, inbuf, 0, i, 64);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Transform(block);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = 0;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = 0;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Buffer remaining input */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Memcpy(buffer, inbuf, index, i, inputLen - i);</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * md5Final整理和填写输出结果<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private void md5Final() {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] bits = new byte[8];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int index, padLen;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Save number of bits */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Encode(bits, count, 8);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Pad out to 56 mod 64.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = (int) (count[0] &gt;&gt;&gt; 3) &amp; 0x3f;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; padLen = (index &lt; 56) ? (56 - index) : (120 - index);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Update(PADDING, padLen);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Append length (before padding) */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md5Update(bits, 8);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///* Store state in digest */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Encode(digest, state, 16);</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * md5Memcpy是一个内部使用的byte数组的块拷贝函数，从input的inpos开始把len长度的<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 字节拷贝到output的outpos位置开始<BR>&nbsp;&nbsp;&nbsp;&nbsp; */</P>
<P>&nbsp;&nbsp;&nbsp; private void md5Memcpy(byte[] output, byte[] input, int outpos, int inpos,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int len) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; len; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[outpos + i] = input[inpos + i];<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * md5Transform是MD5核心变换程序，有md5Update调用，block是分块的原始字节<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private void md5Transform(byte block[]) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long a = state[0], b = state[1], c = state[2], d = state[3];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; long[] x = new long[16];</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Decode(x, block, 64);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Round 1 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = FF(a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = FF(d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = FF(c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = FF(b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = FF(a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = FF(d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = FF(c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = FF(b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = FF(a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = FF(d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = FF(c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = FF(b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = FF(a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = FF(d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = FF(c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = FF(b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Round 2 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = GG(a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = GG(d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = GG(c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = GG(a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = GG(d, a, b, c, x[10], S22, 0x2441453L); /* 22 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = GG(c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = GG(a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = GG(d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = GG(c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = GG(b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = GG(a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = GG(c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Round 3 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = HH(a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = HH(d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = HH(c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = HH(b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = HH(a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = HH(b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = HH(a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = HH(d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = HH(c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = HH(b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = HH(a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = HH(d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = HH(b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Round 4 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = II(a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = II(d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = II(c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = II(b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = II(a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = II(d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = II(c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = II(b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = II(a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = II(c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = II(b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = II(a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = II(d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = II(c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = II(b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[0] += a;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[1] += b;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[2] += c;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state[3] += d;</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * Encode把long数组按顺序拆成byte数组，因为java的long类型是64bit的， 只拆低32bit，以适应原始C实现的用途<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private void Encode(byte[] output, long[] input, int len) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0, j = 0; j &lt; len; i++, j += 4) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[j] = (byte) (input[i] &amp; 0xffL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[j + 1] = (byte) ((input[i] &gt;&gt;&gt; 8) &amp; 0xffL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[j + 2] = (byte) ((input[i] &gt;&gt;&gt; 16) &amp; 0xffL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[j + 3] = (byte) ((input[i] &gt;&gt;&gt; 24) &amp; 0xffL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * Decode把byte数组按顺序合成成long数组，因为java的long类型是64bit的，<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 只合成低32bit，高32bit清零，以适应原始C实现的用途<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; private void Decode(long[] output, byte[] input, int len) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int i, j;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i = 0, j = 0; j &lt; len; i++, j += 4)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output[i] = b2iu(input[j]) | (b2iu(input[j + 1]) &lt;&lt; 8)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | (b2iu(input[j + 2]) &lt;&lt; 16) | (b2iu(input[j + 3]) &lt;&lt; 24);</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * b2iu是我写的一个把byte按照不考虑正负号的原则的＂升位＂程序，因为java没有unsigned运算<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; public static long b2iu(byte b) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return b &lt; 0 ? b &amp; 0x7F + 128 : b;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; /*<BR>&nbsp;&nbsp;&nbsp;&nbsp; * byteHEX()，用来把一个byte类型的数转换成十六进制的ASCII表示，<BR>&nbsp;&nbsp;&nbsp;&nbsp; * 因为java中的byte的toString无法实现这一点，我们又没有C语言中的 sprintf(outbuf,"%02X",ib)<BR>&nbsp;&nbsp;&nbsp;&nbsp; */<BR>&nbsp;&nbsp;&nbsp; public static String byteHEX(byte ib) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'B', 'C', 'D', 'E', 'F' };<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char[] ob = new char[2];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ob[0] = Digit[(ib &gt;&gt;&gt; 4) &amp; 0X0F];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ob[1] = Digit[ib &amp; 0X0F];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String s = new String(ob);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return s;<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp; public static void main(String args[]) {</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MD5 m = new MD5();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (Array.getLength(args) == 0) { <A href="file://如">file://如</A>果没有参数，执行标准的Test Suite</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5 Test suite:");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"850817\"):" + m.getMD5ofStr("850817"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"\"):" + m.getMD5ofStr(""));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"a\"):" + m.getMD5ofStr("a"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"abc\"):" + m.getMD5ofStr("abc"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"message digest\"):"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + m.getMD5ofStr("message digest"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("MD5(\"abcdefghijklmnopqrstuvwxyz\"):"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .println("MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; + m<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));</P>
<P>&nbsp;&nbsp;&nbsp; }</P>
<P>}</P><img src ="http://www.blogjava.net/ZengChang/aggbug/26192.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2005-12-31 16:28 <a href="http://www.blogjava.net/ZengChang/archive/2005/12/31/26192.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jdbc事务</title><link>http://www.blogjava.net/ZengChang/archive/2005/12/31/26189.html</link><dc:creator>ZengChang</dc:creator><author>ZengChang</author><pubDate>Sat, 31 Dec 2005 08:18:00 GMT</pubDate><guid>http://www.blogjava.net/ZengChang/archive/2005/12/31/26189.html</guid><wfw:comment>http://www.blogjava.net/ZengChang/comments/26189.html</wfw:comment><comments>http://www.blogjava.net/ZengChang/archive/2005/12/31/26189.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ZengChang/comments/commentRss/26189.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ZengChang/services/trackbacks/26189.html</trackback:ping><description><![CDATA[<STRONG>
<P>JDBC对数据库的事务操作<BR></P>
<P>1．&nbsp;&nbsp;概述：<BR><BR>在jdbc的数据库操作中，一项事务是由一条或是多条表达式所组成的一个不可分割的工作单元。通过提交commit()或是回滚rollback（）来结束事务的操作。关于事务操作的方法都位于接口java.sql.Connection中。<BR><BR>2．&nbsp;&nbsp;特点：<BR>★ 在jdbc中，事务操作缺省是自动提交。也就是说，一条对数据库的更新表达式代表一项事务操作，操作成功后，系统将自动调用commit()来提交，否则将调用rollback()来回滚。<BR>★ 在jdbc中，可以通过调用setAutoCommit(false)来禁止自动提交。之后就可以把多个数据库操作的表达式作为一个事务，在操作完成后调用commit()来进行整体提交，倘若其中一个表达式操作失败，都不会执行到commit()，并且将产生响应的异常；此时就可以在异常捕获时调用rollback()进行回滚。这样做可以保持多次更新操作后，相关数据的一致性，示例如下：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;try {<BR><BR>conn = <BR><BR>DriverManager.getConnection&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>("jdbc:oracle:thin:@host:1521:SID","username","userpwd";<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setAutoCommit(false);//禁止自动提交，设置回滚点<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stmt = conn.createStatement();<BR><BR>stmt.executeUpdate(“update table …”); //数据库更新操作1<BR><BR>stmt.executeUpdate(“insert into table …”); //数据库更新操作2<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.commit(); //事务提交<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; }catch(Exception ex) {&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.rollback(); //操作不成功则回滚<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}catch(Exception e) {<BR><BR>e.printStackTrace();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR><BR>}<BR><BR><BR><BR>★&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbc API支持事务对数据库的加锁，并且提供了5种操作支持，2种加锁密度。<BR><BR>５种支持：<BR><BR>static int TRANSACTION_NONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 0; <BR><BR>→禁止事务操作和加锁。<BR><BR>static&nbsp;&nbsp;int TRANSACTION_READ_UNCOMMITTED&nbsp;&nbsp;&nbsp;&nbsp;= 1;<BR><BR>→允许脏数据读写(dirty reads)、重复读写(repeatable reads)和影象读写（phntom <BR><BR>reads）<BR><BR>static&nbsp;&nbsp;int TRANSACTION_READ_COMMITTED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 2;<BR><BR>→禁止脏数据读写(dirty reads)，允许重复读写(repeatable reads)和影象读写（phntom reads）<BR><BR>static&nbsp;&nbsp;int TRANSACTION_REPEATABLE_READ&nbsp;&nbsp;&nbsp;&nbsp; = 4;<BR><BR>→禁止脏数据读写(dirty reads)和重复读写(repeatable reads)，允许影象读写（phntom reads）<BR><BR>static&nbsp;&nbsp;int TRANSACTION_SERIALIZABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= 8;<BR><BR>→禁止脏数据读写(dirty reads)、重复读写(repeatable reads)和允许影象读写(phntom reads)<BR><BR>2种密度：<BR><BR>最后一项为表加锁，其余3～4项为行加锁。 <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;脏数据读写(dirty reads):当一个事务修改了某一数据行的值而未提交时，另一事务读取了此行值。倘若前一事务发生了回滚，则后一事务将得到一个无效的值（脏数据）。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重复读写(repeatable reads):当一个事务在读取某一数据行时，另一事务同时在修改此数据行。则前一事务在重复读取此行时将得到一个不一致的值。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;影象读写(phantomreads):当一个事务在某一表中进行数据查询时，另一事务恰好插入了满足了查询条件的数据行。则前一事务在重复读取满足条件的值时，将得到一个额外的“影象“值。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; Jdbc根据数据库提供的缺省值来设置事务支持及其加锁，当然，也可以手工设置：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;setTransactionIsolation（TRANSACTION_READ_UNCOMMITTED）;<BR><BR>可以查看数据库的当前设置：<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;getTransactionIsolation()<BR><BR>需要注意的是，在进行受动设置时，数据库及其驱动程序必须得支持相应的事务操作操作才行。<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 上述设置随着值的增加，其事务的独立性增加，更能有效的防止事务操作之间的冲突；同时也增加了加锁的开销，降低了用户之间访问数据库的并发性，程序的运行效率也回随之降低。因此得平衡程序运行效率和数据一致性之间的冲突。一般来说，对于只涉及到数据库的查询操作时，可以采用TRANSACTION_READ_UNCOMMITTED方式；对于数据查询远多于更新的操作，可以采用TRANSACTION_READ_COMMITTED方式；对于更新操作较多的，可以采用TRANSACTION_REPEATABLE_READ；在数据一致性要求更高的场合再考虑最后一项，由于涉及到表加锁，因此会对程序运行效率产生较大的影响。<BR><BR>另外，在oracle中数据库驱动对事务处理的缺省值是TRANSACTION_NONE，即不支持事务操作，所以需要在程序中手动进行设置。<BR><BR>3．&nbsp;&nbsp;小结<BR><BR>jdbc提供的对数据库事务操作的支持是比较完整的，通过事务操作可以提高程序的运行效率，保持数据的一致性</P></STRONG><img src ="http://www.blogjava.net/ZengChang/aggbug/26189.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ZengChang/" target="_blank">ZengChang</a> 2005-12-31 16:18 <a href="http://www.blogjava.net/ZengChang/archive/2005/12/31/26189.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>