﻿<?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-ruey</title><link>http://www.blogjava.net/ruey/</link><description /><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 09:00:15 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 09:00:15 GMT</pubDate><ttl>60</ttl><item><title>PNG格式</title><link>http://www.blogjava.net/ruey/archive/2005/04/22/3618.html</link><dc:creator>瑞</dc:creator><author>瑞</author><pubDate>Fri, 22 Apr 2005 07:57:00 GMT</pubDate><guid>http://www.blogjava.net/ruey/archive/2005/04/22/3618.html</guid><wfw:comment>http://www.blogjava.net/ruey/comments/3618.html</wfw:comment><comments>http://www.blogjava.net/ruey/archive/2005/04/22/3618.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruey/comments/commentRss/3618.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruey/services/trackbacks/3618.html</trackback:ping><description><![CDATA[<FONT size=2>PNG是20世纪90年代中期开始开发的图像文件存储格式，其目的是企图替代GIF和TIFF文件格式，同时增加一些GIF文件格式所不具备的特性。流式网络图形格式(Portable Network Graphic Format，PNG)名称来源于非官方的“PNG's Not GIF”，是一种位图文件(bitmap file)存储格式，读成“ping”。PNG用来存储灰度图像时，灰度图像的深度可多到16位，存储彩色图像时，彩色图像的深度可多到48位，并且还可存储多到16位的α通道数据。PNG使用从LZ77派生的无损数据压缩算法。</FONT> 
<P><FONT size=2>PNG文件格式保留GIF文件格式的下列特性：</FONT></P>
<OL>
<LI><FONT size=2>使用彩色查找表或者叫做调色板可支持256种颜色的彩色图像。 </FONT>
<LI><FONT size=2>流式读/写性能(streamability)：图像文件格式允许连续读出和写入图像数据，这个特性很适合于在通信过程中生成和显示图像。 </FONT>
<LI><FONT size=2>逐次逼近显示(progressive display)：这种特性可使在通信链路上传输图像文件的同时就在终端上显示图像，把整个轮廓显示出来之后逐步显示图像的细节，也就是先用低分辨率显示图像，然后逐步提高它的分辨率。 </FONT>
<LI><FONT size=2>透明性(transparency)：这个性能可使图像中某些部分不显示出来，用来创建一些有特色的图像。 </FONT>
<LI><FONT size=2>辅助信息(ancillary information)：这个特性可用来在图像文件中存储一些文本注释信息。 </FONT>
<LI><FONT size=2>独立于计算机软硬件环境。 </FONT>
<LI><FONT size=2>使用无损压缩。</FONT> </LI></OL>
<P><FONT size=2>PNG文件格式中要增加下列GIF文件格式所没有的特性：</FONT></P>
<OL>
<LI><FONT size=2>每个像素为48位的真彩色图像。 </FONT>
<LI><FONT size=2>每个像素为16位的灰度图像。 </FONT>
<LI><FONT size=2>可为灰度图和真彩色图添加α通道。 </FONT>
<LI><FONT size=2>添加图像的γ信息。 </FONT>
<LI><FONT size=2>使用循环冗余码(<B>c</B>yclic <B>r</B>edundancy <B>c</B>ode，CRC)检测损害的文件。 </FONT>
<LI><FONT size=2>加快图像显示的逐次逼近显示方式。 </FONT>
<LI><FONT size=2>标准的读/写工具包。 </FONT>
<LI><FONT size=2>可在一个文件中存储多幅图像。</FONT> </LI></OL>
<DIR><FONT lang=ZH-CN color=#ff0000 size=2><B>
<P>文件结构</P></DIR></B></FONT><FONT lang=ZH-CN>
<P><FONT size=2>PNG图像格式文件(或者称为数据流)由一个8字节的PNG文件署名(PNG file signature)域和按照特定结构组织的3个以上的数据块(chunk)组成。</FONT></P>
<P><FONT size=2>PNG定义了两种类型的数据块，一种是称为关键数据块(critical chunk)，这是标准的数据块，另一种叫做辅助数据块(ancillary chunks)，这是可选的数据块。关键数据块定义了4个标准数据块，每个PNG文件都必须包含它们，PNG读写软件也都必须要支持这些数据块。虽然PNG文件规范没有要求PNG编译码器对可选数据块进行编码和译码，但规范提倡支持可选数据块。</FONT></P></FONT><FONT lang=ZH-CN color=#800080 size=2><B>
<P>(1) PNG文件署名域</P></B></FONT><FONT lang=ZH-CN size=2>
<P>8字节的PNG文件署名域用来识别该文件是不是PNG文件。该域的值是：</P></FONT>
<CENTER>
<TABLE id=table5 cellSpacing=0 cellPadding=1 width=278 border=0>
<TBODY>
<TR>
<TD vAlign=top width="29%"><FONT lang=ZH-CN size=2>十进制数</FONT></TD>
<TD vAlign=top width="11%"><FONT lang=ZH-CN size=2>137</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>80</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>78</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>71</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>13</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>10</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>26</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>10</FONT></TD></TR>
<TR>
<TD vAlign=top width="29%"><FONT lang=ZH-CN size=2>十六进制数</FONT></TD>
<TD vAlign=top width="11%"><FONT lang=ZH-CN size=2>89</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>50</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>4e</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>47</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>0d</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>0a</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>1a</FONT></TD>
<TD vAlign=top width="9%"><FONT lang=ZH-CN size=2>0a</FONT></TD></TR></TBODY></TABLE></CENTER><FONT lang=ZH-CN size=2>
<P>　</P></FONT><FONT lang=ZH-CN color=#800080 size=2><B>
<P>(2) 数据块的结构</P></B></FONT><FONT lang=ZH-CN>
<P><FONT size=2>每个数据块都由表6-07所示的的4个域组成。</FONT></P>
<DIR><B>
<P align=center><FONT size=2>表6-07 PNG文件数据块的结构</FONT></P></DIR></B></FONT>
<CENTER>
<TABLE id=table6 borderColor=#000000 cellSpacing=2 cellPadding=1 width=557 border=1>
<TBODY>
<TR>
<TD vAlign=top width="37%"><FONT lang=ZH-CN size=2><B>
<P align=center>名称</B></FONT></P></TD>
<TD vAlign=top width="12%"><FONT lang=ZH-CN size=2><B>
<P align=center>字节数</B></FONT></P></TD>
<TD vAlign=top width="51%"><FONT lang=ZH-CN size=2><B>
<P align=center>说明</B></FONT></P></TD></TR>
<TR>
<TD vAlign=top width="37%"><FONT lang=ZH-CN size=2>Length(长度)</FONT></TD>
<TD vAlign=top width="12%"><FONT lang=ZH-CN size=2>4字节</FONT></TD>
<TD vAlign=top width="51%"><FONT lang=ZH-CN size=2>指定数据块中数据域的长度，其长度不超过<BR>(2<SUP>31</SUP>－1)字节</FONT></TD></TR>
<TR>
<TD vAlign=top width="37%"><FONT lang=ZH-CN size=2>Chunk Type Code(数据块类型码)</FONT></TD>
<TD vAlign=top width="12%"><FONT lang=ZH-CN size=2>4字节</FONT></TD>
<TD vAlign=top width="51%"><FONT lang=ZH-CN size=2>数据块类型码由ASCII字母(A-Z和a-z)组成</FONT></TD></TR>
<TR>
<TD vAlign=top width="37%"><FONT lang=ZH-CN size=2>Chunk Data(数据块数据)</FONT></TD>
<TD vAlign=top width="12%"><FONT lang=ZH-CN size=2>可变长度</FONT></TD>
<TD vAlign=top width="51%"><FONT lang=ZH-CN size=2>存储按照Chunk Type Code指定的数据</FONT></TD></TR>
<TR>
<TD vAlign=top width="37%"><FONT lang=ZH-CN size=2>CRC(循环冗余检测)</FONT></TD>
<TD vAlign=top width="12%"><FONT lang=ZH-CN size=2>4字节</FONT></TD>
<TD vAlign=top width="51%"><FONT lang=ZH-CN size=2>存储用来检测是否有错误的循环冗余码</FONT></TD></TR></TBODY></TABLE></CENTER>
<P>　</P><FONT lang=ZH-CN>
<P><FONT size=2>在表6-07中，CRC(<B>c</B>yclic <B>r</B>edundancy <B>c</B>heck)域中的值是对Chunk Type Code域和Chunk Data域中的数据进行计算得到的。CRC具体算法定义在ISO 3309和ITU-T V.42中，其值按下面的CRC码生成多项式进行计算：</FONT></P>
<P><FONT size=2>x<SUP>32</SUP>+x<SUP>26</SUP>+x<SUP>23</SUP>+x<SUP>22</SUP>+x<SUP>16</SUP>+x<SUP>12</SUP>+x<SUP>11</SUP>+x<SUP>10</SUP>+x<SUP>8</SUP>+x<SUP>7</SUP>+x<SUP>5</SUP>+x<SUP>4</SUP>+x<SUP>2</SUP>+x+1</FONT></P></FONT>
<DIR><B><FONT lang=ZH-CN color=#ff0000 size=2>
<P>数据块结构</P></DIR></FONT><FONT lang=ZH-CN color=#800080 size=2>
<P>1. 关键数据块</P></FONT></B><FONT lang=ZH-CN>
<P><FONT size=2>关键数据块中的4个标准数据块是：</FONT></P>
<P><FONT size=2>(1) 文件头数据块IHDR(header chunk)：它包含有PNG文件中存储的图像数据的基本信息，并要作为第一个数据块出现在PNG数据流中，而且一个PNG数据流中只能有一个文件头数据块。</FONT></P>
<P><FONT size=2>文件头数据块由13字节组成，它的格式如表6-08所示。</FONT></P>
<DIR><B>
<P align=center><FONT size=2>表6-08 PNG文件头键数据块的结构</FONT></P></DIR></B></FONT>
<CENTER>
<TABLE id=table7 borderColor=#000000 cellSpacing=2 width=460 border=1>
<TBODY>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>
<P align=center>域的名称</FONT></P></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>
<P align=center>字节数</FONT></P></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>
<P align=center>说明</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Width</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>4 bytes</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>图像宽度，以像素为单位</FONT></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Height</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>4 bytes</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>图像高度，以像素为单位</FONT></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Bit depth</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>图像深度：<BR>索引彩色图像：1，2，4或8<BR>灰度图像：1，2，4，8或16<BR>真彩色图像：8或16</FONT></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>ColorType</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN><FONT size=2>颜色类型：<BR>0：灰度图像, 1，2，4，8或16<BR>2：真彩色图像，8或16<BR>3：索引彩色图像，1，2，4或8</FONT> 
<P><FONT size=2>4：带α通道数据的灰度图像，8或16<BR>6：带α通道数据的真彩色图像，8或16</FONT></FONT></P></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Compression method</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>压缩方法(LZ77派生算法)</FONT></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Filter method</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN size=2>滤波器方法</FONT></TD></TR>
<TR>
<TD vAlign=top width="27%"><FONT lang=ZH-CN size=2>Interlace method</FONT></TD>
<TD vAlign=top width="17%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="56%"><FONT lang=ZH-CN><FONT size=2>隔行扫描方法：</FONT> 
<P><FONT size=2>0：非隔行扫描</FONT></P>
<P><FONT size=2>1： Adam7(由Adam M. Costello开发的7 <BR>遍隔行扫描方法)</FONT></FONT></P></TD></TR></TBODY></TABLE></CENTER>
<P>　</P><FONT lang=ZH-CN>
<P><FONT size=2>(2) 调色板数据块PLTE(palette chunk)：它包含有与索引彩色图像((indexed-color image))相关的彩色变换数据，它仅与索引彩色图像有关，而且要放在图像数据块(image data chunk)之前。真彩色的PNG数据流也可以有调色板数据块，目的是便于非真彩色显示程序用它来量化图像数据，从而显示该图像。调色板数据块结构如表6-09所示。</FONT></P>
<DIR><B>
<P align=center><FONT size=2>表6-09 调色板数据块结构</FONT></P></DIR></B></FONT>
<CENTER>
<TABLE id=table8 borderColor=#000000 cellSpacing=2 cellPadding=1 width=234 border=1>
<TBODY>
<TR>
<TD vAlign=top width="28%"><FONT lang=ZH-CN size=2>
<P align=center>域的名称</FONT></P></TD>
<TD vAlign=top width="22%"><FONT lang=ZH-CN size=2>
<P align=center>字节数</FONT></P></TD>
<TD vAlign=top width="50%"><FONT lang=ZH-CN size=2>
<P align=center>说明</FONT></P></TD></TR>
<TR>
<TD vAlign=top width="28%"><FONT lang=ZH-CN size=2>Red</FONT></TD>
<TD vAlign=top width="22%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="50%"><FONT lang=ZH-CN size=2>0 = 黑，255 = 红</FONT></TD></TR>
<TR>
<TD vAlign=top width="28%"><FONT lang=ZH-CN size=2>Green</FONT></TD>
<TD vAlign=top width="22%"><FONT size=2>"&gt; </FONT><FONT lang=ZH-CN>
<P><FONT size=2>0 = 黑，255 = 绿</FONT></FONT></P></TD></TR>
<TR>
<TD vAlign=top width="28%"><FONT lang=ZH-CN size=2>Blue</FONT></TD>
<TD vAlign=top width="22%"><FONT lang=ZH-CN size=2>1 byte</FONT></TD>
<TD vAlign=top width="50%"><FONT lang=ZH-CN size=2>0 = 黑，255 = 蓝</FONT></TD></TR></TBODY></TABLE></CENTER>
<P>　</P><FONT lang=ZH-CN>
<P><FONT size=2>调色板实际是一个彩色索引查找表，它的表项数目可以是1～256中的一个数，每个表项有3字节，因此调色板数据块所包含的最大字节数为768。</FONT></P>
<P><FONT size=2>(3) 图像数据块IDAT(image data chunk)：它存储实际的数据，在数据流中可包含多个连续顺序的图像数据块。</FONT></P>
<P><FONT size=2>(4) 图像结束数据IEND(image trailer chunk)：它用来标记PNG文件或者数据流已经结束，并且必须要放在文件的尾部。</FONT></P>
<P><FONT size=2>除了表示数据块开始的IHDR必须放在最前面， 表示PNG文件结束的IEND数据块放在最后面之外，其他数据块的存放顺序没有限制。</FONT></P></FONT><FONT lang=ZH-CN color=#800080 size=2><B>
<P>2. 辅助数据块</P></B></FONT><FONT lang=ZH-CN>
<P><FONT size=2>PNG文件格式规范制定的10个辅助数据块是：</FONT></P>
<P><FONT size=2>(1) 背景颜色数据块bKGD(background color)。</FONT></P>
<P><FONT size=2>(2) 基色和白色度数据块cHRM(primary chromaticities and white point)。所谓白色度是指当R＝G＝B＝最大值时在显示器上产生的白色度。</FONT></P>
<P><FONT size=2>(3) 图像γ数据块gAMA(image gamma)。</FONT></P>
<P><FONT size=2>(4) 图像直方图数据块hIST(image histogram)。</FONT></P>
<P><FONT size=2>(5) 物理像素尺寸数据块pHYs(physical pixel dimensions)。</FONT></P>
<P><FONT size=2>(6) 样本有效位数据块sBIT(significant bits)。</FONT></P>
<P><FONT size=2>(7) 文本信息数据块tEXt(textual data)。</FONT></P>
<P><FONT size=2>(8) 图像最后修改时间数据块tIME (image last-modification time)。</FONT></P>
<P><FONT size=2>(9) 图像透明数据块tRNS (transparency)。</FONT></P>
<P><FONT size=2>(10) 压缩文本数据块zTXt (compressed textual data)。</FONT></P></FONT><FONT lang=ZH-CN color=#800080 size=2><B>
<P>3. 数据块摘要</P></B></FONT><FONT lang=ZH-CN>
<P><FONT size=2>关键数据块、辅助数据块和专用公共数据块(special-purpose public chunks)综合在表6-10中。</FONT></P>
<DIR><B>
<P align=center><FONT size=2>表6-10 PNG文件格式中的数据块</FONT></P></DIR></B></FONT>
<CENTER>
<TABLE id=table9 borderColor=#000000 cellSpacing=2 width=532 border=1>
<TBODY>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2><B>
<P align=center>数据块符号</B></FONT></P></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2><B>
<P align=center>数据块名称</B></FONT></P></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2><B>
<P align=center>多数据块</B></FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2><B>
<P align=center>可选否</B></FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2><B>
<P align=center>位置限制</B></FONT></P></TD></TR>
<TR>
<TD vAlign=top width="14%" bgColor=#ffffff><FONT lang=ZH-CN size=2>IHDR</FONT></TD>
<TD vAlign=top width="30%" bgColor=#ffffff><FONT lang=ZH-CN size=2>文件头数据块</FONT></TD>
<TD vAlign=top width="13%" bgColor=#ffffff colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%" bgColor=#ffffff><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="32%" bgColor=#ffffff><FONT lang=ZH-CN size=2>第一块</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>cHRM</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>基色和白色点数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE和IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>gAMA</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>图像γ数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE和IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>sBIT</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>样本有效位数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE和IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%" bgColor=#ffffff><FONT lang=ZH-CN size=2>PLTE</FONT></TD>
<TD vAlign=top width="30%" bgColor=#ffffff><FONT lang=ZH-CN size=2>调色板数据块</FONT></TD>
<TD vAlign=top width="13%" bgColor=#ffffff colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%" bgColor=#ffffff><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%" bgColor=#ffffff><FONT lang=ZH-CN size=2>在IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>bKGD</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>背景颜色数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE之后IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>hIST</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>图像直方图数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE之后IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>tRNS</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>图像透明数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在PLTE之后IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>oFFs</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>pHYs</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>物理像素尺寸数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>sCAL</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>在IDAT之前</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%" bgColor=#ffffff><FONT lang=ZH-CN size=2>IDAT</FONT></TD>
<TD vAlign=top width="30%" bgColor=#ffffff><FONT lang=ZH-CN size=2>图像数据块</FONT></TD>
<TD vAlign=top width="13%" bgColor=#ffffff colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%" bgColor=#ffffff><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="32%" bgColor=#ffffff><FONT lang=ZH-CN size=2>与其他IDAT连续</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>tIME</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>图像最后修改时间数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>tEXt</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>文本信息数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>zTXt</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>压缩文本数据块</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>fRAc</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>gIFg</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>gIFt</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%"><FONT lang=ZH-CN size=2>gIFx</FONT></TD>
<TD vAlign=top width="30%"><FONT lang=ZH-CN size=2>(专用公共数据块)</FONT></TD>
<TD vAlign=top width="13%" colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="10%"><FONT lang=ZH-CN size=2>
<P align=center>是</FONT></P></TD>
<TD vAlign=top width="32%"><FONT lang=ZH-CN size=2>无限制</FONT></TD></TR>
<TR>
<TD vAlign=top width="14%" bgColor=#ffffff><FONT lang=ZH-CN size=2>IEND</FONT></TD>
<TD vAlign=top width="30%" bgColor=#ffffff><FONT lang=ZH-CN size=2>图像结束数据</FONT></TD>
<TD vAlign=top width="13%" bgColor=#ffffff colSpan=3><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="10%" bgColor=#ffffff><FONT lang=ZH-CN size=2>
<P align=center>否</FONT></P></TD>
<TD vAlign=top width="32%" bgColor=#ffffff><FONT lang=ZH-CN size=2>最后一个数据块</FONT></TD></TR></TBODY></TABLE></CENTER>
<P>　</P><FONT lang=ZH-CN size=2>
<P>tEXt和zTXt数据块中的标准关键字：</P></FONT>
<TABLE id=table10 cellSpacing=0 cellPadding=1 width=279 border=0>
<TBODY>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Title</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>图像名称或者标题</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Author</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>图像作者名</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Description</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>图像说明</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Copyright</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>版权声明</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>CreationTime</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>原图创作时间</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Software</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>创作图像使用的软件</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Disclaimer</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>弃权</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Warning</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>图像内容警告</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Source</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>创作图像使用的设备</P></DIR></FONT></TD></TR>
<TR>
<TD vAlign=top width="41%">
<DIR><FONT lang=ZH-CN size=2>
<P>Comment</P></DIR></FONT></TD>
<TD vAlign=top width="59%">
<DIR><FONT lang=ZH-CN size=2>
<P>各种注释</P></DIR></FONT></TD></TR></TBODY></TABLE><img src ="http://www.blogjava.net/ruey/aggbug/3618.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruey/" target="_blank">瑞</a> 2005-04-22 15:57 <a href="http://www.blogjava.net/ruey/archive/2005/04/22/3618.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用Java访问SQL Server 2000数据库</title><link>http://www.blogjava.net/ruey/archive/2005/04/20/3550.html</link><dc:creator>瑞</dc:creator><author>瑞</author><pubDate>Wed, 20 Apr 2005 14:09:00 GMT</pubDate><guid>http://www.blogjava.net/ruey/archive/2005/04/20/3550.html</guid><wfw:comment>http://www.blogjava.net/ruey/comments/3550.html</wfw:comment><comments>http://www.blogjava.net/ruey/archive/2005/04/20/3550.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruey/comments/commentRss/3550.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruey/services/trackbacks/3550.html</trackback:ping><description><![CDATA[数据库技术和网络技术是当今计算机领域的两大热门话题，数据库技术自产生以来，在技术上已发展成熟。而作为前端访问的开发工具和环境仍处在不断完善和发展之中，除了网络上使用的ASP、PHP、JSP作为前端连接数据库技术外，小型系统上常用访问数据库技术有Delphi、Visual Basic、PowerBuilder及VC++等，而Java也是其中之一。
<P>　　Java语言是编写数据库应用程序的杰出语言之一，它提供了方便访问数据的技术。利用Java语言中的JDBC技术，用户能方便地开发出基于Web网页的数据库访问程序，从而扩充网络应用功能。JDBC（Java Database Connectivity，Java数据库连接）是一种用于执行SQL语句的Java API，可以为多种关系数据库提供统一的访问接口。JDBC由一组用Java语言编写的类与接口组成，通过调用这些类和接口所提供的方法，用户能够以一致的方式连接多种不同的数据库系统（如Access、SQL Server 2000、Oracle、Sybase等），进而可使用标准的SQL语言来存取数据库中的数据，而不必再为每一种数据库系统编写不同的Java程序代码。</P>
<P>　　SQL Server2000是微软公司新一代的数据库产品，它是在SQL Server7.0建立的坚固基础上产生的，并对SQL Server7.0做了大量扩展。SQL Server2000通过高端硬件平台以及最新网络和存储技术的支持，可为最大的Web站点和企业级应用提供可扩展性和高可靠性。</P>
<P>　　Java通过JDBC、ODBC接口访问数据库</P>
<P>　　1 JDBC、ODBC接口</P>
<P>　　Java应用程序通过JDBC API(java.sql)与数据库连接，而实际的动作则是由JDBC驱动程序管理器(JDBC Driver Manager)通过JDBC驱动程序与数据库系统进行连接。ODBC（Open DataBase Connectivity）即开放式的接口，它为用户提供了一个访问关系数据库的标准接口，对于不同的数据库它提供了一套统一的API；可以使应用程序通过API访问任何提供了ODBC驱动程序的数据库，而目前所有的关系数据库都提供了ODBC驱动程序，所以ODBC已经成为数据库访问的业界标准，并得到了广泛应用。</P>
<P>　　JDBC-ODBC桥是一种JDBC驱动程序，它通过将JDBC操作转换为ODBC操作来实现的。利用JDBC-ODBC桥可以使程序开发人员不需要学习更多的知识就可以编写JDBC应用程序，并能够充分利用现有的ODBC数据源。JDBC-ODBC桥驱动程序可以使JDBC能够访问几乎所有类型的数据库。</P>
<P>　　2 利用Java应用程序访问SQL Server2000数据库</P>
<P>　　（1）建立数据库</P>
<P>　　启动“Microsoft SQL Server2000”，打开“企业管理器”在“数据库”中建立名为“mydata”的数据库，并在其下制作名为“wuzi”的数据表，如图1所示。</P>
<P><IMG onerror="this.src='http://www.yesky.com/image20010518/212105.bmp';" hspace=3 src="http://myhard.yesky.com/image20010518/212105.bmp" align=center vspace=1 border=1></P>
<P>图1</P>
<P>　　（2）建立（ODBC）数据源和驱动程序</P>
<P>　　在控制面板上通过“管理工具”的“数据源（ODBC）”打开“ODBC数据源管理器”对话框，单击“系统DSN”选项卡，然后单击“添加”按钮，得到“创建数据源”对话框，选择“SQL Server”并单击“完成”按钮，在出现的“建立新的数据源到SQL Server”对话框中的“数据源名称”项填写“wzgl”并选取“服务器名”，然后单击“下一步”按钮，选择“使用网络登录ID的Windows NT验证”项目，单击“下一步”按钮，把默认的数据库改为“mydata”，再单击“下一步”，单击“完成”按钮，然后可以单击“测试数据源”，成功后，单击“确定”按钮，完成了（ODBC）数据源和驱动程序的建立。</P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">import java.awt.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.awt.</SPAN><SPAN style="COLOR: #0000ff">event</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.sql.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> jdbc </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">定义主类</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_88_194_Open_Image onclick="this.style.display='none'; Codehighlighter1_88_194_Open_Text.style.display='none'; Codehighlighter1_88_194_Closed_Image.style.display='inline'; Codehighlighter1_88_194_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_88_194_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_88_194_Closed_Text.style.display='none'; Codehighlighter1_88_194_Open_Image.style.display='inline'; Codehighlighter1_88_194_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_88_194_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_88_194_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> main(String args[])<BR><IMG id=Codehighlighter1_131_192_Open_Image onclick="this.style.display='none'; Codehighlighter1_131_192_Open_Text.style.display='none'; Codehighlighter1_131_192_Closed_Image.style.display='inline'; Codehighlighter1_131_192_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_131_192_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_131_192_Closed_Text.style.display='none'; Codehighlighter1_131_192_Open_Image.style.display='inline'; Codehighlighter1_131_192_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　</SPAN><SPAN id=Codehighlighter1_131_192_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_131_192_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　GUI gui</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> GUI(); </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">创建类GUI的对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　　gui.pack(); </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">装载执行GUI类</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> GUI extends Frame implements Action Listener <BR><IMG id=Codehighlighter1_248_1948_Open_Image onclick="this.style.display='none'; Codehighlighter1_248_1948_Open_Text.style.display='none'; Codehighlighter1_248_1948_Closed_Image.style.display='inline'; Codehighlighter1_248_1948_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_248_1948_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_248_1948_Closed_Text.style.display='none'; Codehighlighter1_248_1948_Open_Image.style.display='inline'; Codehighlighter1_248_1948_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_248_1948_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_248_1948_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　TextArea text; Panel panel; TextField sno; Button btn; <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　GUI() </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">构造方法</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_322_840_Open_Image onclick="this.style.display='none'; Codehighlighter1_322_840_Open_Text.style.display='none'; Codehighlighter1_322_840_Closed_Image.style.display='inline'; Codehighlighter1_322_840_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_322_840_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_322_840_Closed_Text.style.display='none'; Codehighlighter1_322_840_Open_Image.style.display='inline'; Codehighlighter1_322_840_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　</SPAN><SPAN id=Codehighlighter1_322_840_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_322_840_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　super(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">物资情况查询</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);setLayout(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> BorderLayout()); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　setBackground(Color.cyan); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　setVisible(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);text</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> TextArea(); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　btn</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Button(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">查询</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　sno</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> TextField(</SPAN><SPAN style="COLOR: #000000">16</SPAN><SPAN style="COLOR: #000000">); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　panel</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Panel(); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　panel.add(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> Label(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">输入被查询的物资编号：</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　panel.add(sno); panel.add(btn); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　add(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">North</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,panel); add(text,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Center</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　text.setEditable(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);btn.addActionListener(</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　addWindowListener(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> WindowAdapter() <BR><IMG id=Codehighlighter1_734_836_Open_Image onclick="this.style.display='none'; Codehighlighter1_734_836_Open_Text.style.display='none'; Codehighlighter1_734_836_Closed_Image.style.display='inline'; Codehighlighter1_734_836_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_734_836_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_734_836_Closed_Text.style.display='none'; Codehighlighter1_734_836_Open_Image.style.display='inline'; Codehighlighter1_734_836_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　　</SPAN><SPAN id=Codehighlighter1_734_836_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_734_836_Open_Text><SPAN style="COLOR: #000000">{ <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> windowClosing(WindowEvent e)<BR><IMG id=Codehighlighter1_784_833_Open_Image onclick="this.style.display='none'; Codehighlighter1_784_833_Open_Text.style.display='none'; Codehighlighter1_784_833_Closed_Image.style.display='inline'; Codehighlighter1_784_833_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_784_833_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_784_833_Closed_Text.style.display='none'; Codehighlighter1_784_833_Open_Image.style.display='inline'; Codehighlighter1_784_833_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　　　</SPAN><SPAN id=Codehighlighter1_784_833_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_784_833_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　　setVisible(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　　System.exit(</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　　　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　}</SPAN></SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_885_1031_Open_Image onclick="this.style.display='none'; Codehighlighter1_885_1031_Open_Text.style.display='none'; Codehighlighter1_885_1031_Closed_Image.style.display='inline'; Codehighlighter1_885_1031_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_885_1031_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_885_1031_Closed_Text.style.display='none'; Codehighlighter1_885_1031_Open_Image.style.display='inline'; Codehighlighter1_885_1031_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> actionPerformed(ActionEvent e) </SPAN><SPAN id=Codehighlighter1_885_1031_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_885_1031_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(e.getSource()</SPAN><SPAN style="COLOR: #000000">==</SPAN><SPAN style="COLOR: #000000">btn) </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">当用户按下查询按钮时</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_925_1029_Open_Image onclick="this.style.display='none'; Codehighlighter1_925_1029_Open_Text.style.display='none'; Codehighlighter1_925_1029_Closed_Image.style.display='inline'; Codehighlighter1_925_1029_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_925_1029_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_925_1029_Closed_Text.style.display='none'; Codehighlighter1_925_1029_Open_Image.style.display='inline'; Codehighlighter1_925_1029_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　</SPAN><SPAN id=Codehighlighter1_925_1029_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_925_1029_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　text.setText(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">查询结果</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">); </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">显示提示信息</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　　</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_974_997_Open_Image onclick="this.style.display='none'; Codehighlighter1_974_997_Open_Text.style.display='none'; Codehighlighter1_974_997_Closed_Image.style.display='inline'; Codehighlighter1_974_997_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_974_997_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_974_997_Closed_Text.style.display='none'; Codehighlighter1_974_997_Open_Image.style.display='inline'; Codehighlighter1_974_997_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　　</SPAN><SPAN id=Codehighlighter1_974_997_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_974_997_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　Liststudent(); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1024_1026_Open_Image onclick="this.style.display='none'; Codehighlighter1_1024_1026_Open_Text.style.display='none'; Codehighlighter1_1024_1026_Closed_Image.style.display='inline'; Codehighlighter1_1024_1026_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1024_1026_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1024_1026_Closed_Text.style.display='none'; Codehighlighter1_1024_1026_Open_Image.style.display='inline'; Codehighlighter1_1024_1026_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　　</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(SQLException ee) </SPAN><SPAN id=Codehighlighter1_1024_1026_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1024_1026_Open_Text><SPAN style="COLOR: #000000">{ }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> Liststudent() throws SQLException </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">针对数据库的操作</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_1090_1946_Open_Image onclick="this.style.display='none'; Codehighlighter1_1090_1946_Open_Text.style.display='none'; Codehighlighter1_1090_1946_Closed_Image.style.display='inline'; Codehighlighter1_1090_1946_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1090_1946_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1090_1946_Closed_Text.style.display='none'; Codehighlighter1_1090_1946_Open_Image.style.display='inline'; Codehighlighter1_1090_1946_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_1090_1946_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1090_1946_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　String bh,mc,xh,lb,dw,sj; <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000"> sl; </SPAN><SPAN style="COLOR: #0000ff">float</SPAN><SPAN style="COLOR: #000000"> dj,je; <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1149_1201_Open_Image onclick="this.style.display='none'; Codehighlighter1_1149_1201_Open_Text.style.display='none'; Codehighlighter1_1149_1201_Closed_Image.style.display='inline'; Codehighlighter1_1149_1201_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1149_1201_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1149_1201_Closed_Text.style.display='none'; Codehighlighter1_1149_1201_Open_Image.style.display='inline'; Codehighlighter1_1149_1201_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　</SPAN><SPAN id=Codehighlighter1_1149_1201_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1149_1201_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　Class.forName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">sun.jdbc.odbc.JdbcOdbcDriver</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_1236_1238_Open_Image onclick="this.style.display='none'; Codehighlighter1_1236_1238_Open_Text.style.display='none'; Codehighlighter1_1236_1238_Closed_Image.style.display='inline'; Codehighlighter1_1236_1238_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1236_1238_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1236_1238_Closed_Text.style.display='none'; Codehighlighter1_1236_1238_Open_Image.style.display='inline'; Codehighlighter1_1236_1238_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(ClassNotFoundException e) </SPAN><SPAN id=Codehighlighter1_1236_1238_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1236_1238_Open_Text><SPAN style="COLOR: #000000">{ }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　Connection con</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">DriverManager.getConnection(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">jdbc:odbc:wzgl</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　Statement sql</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">con.createStatement(); </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">创建Statement对象</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　ResultSet rs</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">sql.executeQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">select * from wuzi</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　</SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(rs.next()) </SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">输出被查询的情况</SPAN><SPAN style="COLOR: #008000"><BR><IMG id=Codehighlighter1_1442_1943_Open_Image onclick="this.style.display='none'; Codehighlighter1_1442_1943_Open_Text.style.display='none'; Codehighlighter1_1442_1943_Closed_Image.style.display='inline'; Codehighlighter1_1442_1943_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1442_1943_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1442_1943_Closed_Text.style.display='none'; Codehighlighter1_1442_1943_Open_Image.style.display='inline'; Codehighlighter1_1442_1943_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">　</SPAN><SPAN id=Codehighlighter1_1442_1943_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1442_1943_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　bh</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">物资编号</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　mc</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">物资名称</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　xh</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">规格型号</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　lb</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">类别</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　dw</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">计量单位</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　sl</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getInt(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">数量</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　dj</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getFloat(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">单价</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　je</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getFloat(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">金额</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　sj</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">rs.getDate(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">时间</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).toString(); <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(bh.trim().equals(sno.getText().trim())) <BR><IMG id=Codehighlighter1_1730_1940_Open_Image onclick="this.style.display='none'; Codehighlighter1_1730_1940_Open_Text.style.display='none'; Codehighlighter1_1730_1940_Closed_Image.style.display='inline'; Codehighlighter1_1730_1940_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_1730_1940_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1730_1940_Closed_Text.style.display='none'; Codehighlighter1_1730_1940_Open_Image.style.display='inline'; Codehighlighter1_1730_1940_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>　　</SPAN><SPAN id=Codehighlighter1_1730_1940_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_1730_1940_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　text.append(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">物资编号</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">物资名称</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">规格型号</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">类别</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">计量单位</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">数量</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">单价</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">金额</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">时间</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>　　　text.append(</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">bh</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">mc</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">xh</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">lb</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">dw</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">sl</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">dj</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">je</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">sj</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">\n</SPAN><SPAN style="COLOR: #000000">'</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　　}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>　}</SPAN></SPAN><SPAN style="COLOR: #000000"> <BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></DIV></DIV>执行后在文本框中输入要查询物资的物资编号，单击“查询”按钮，在下面的文本框中显示被查询物资的所有信息。如图2所示。<BR><IMG onerror="this.src='http://www.yesky.com/image20010518/212109.bmp';" hspace=3 src="http://myhard.yesky.com/image20010518/212109.bmp" align=center vspace=1 border=1><BR><BR>图2
<P>　　结束语</P>
<P>　　本文只涉及到对SQL Server2000数据库访问的查询操作，也可以进行插入、删除、修改等操作。随着数据库技术的迅猛发展和Java版本的不断升级，利用Java对数据库的访问会越来越简单，并且应用的范围也会越来越广，当然还会有许多新的功能等待我们去开发。<BR></P><img src ="http://www.blogjava.net/ruey/aggbug/3550.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruey/" target="_blank">瑞</a> 2005-04-20 22:09 <a href="http://www.blogjava.net/ruey/archive/2005/04/20/3550.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基本的JDBC数据库访问流程</title><link>http://www.blogjava.net/ruey/archive/2005/04/20/3540.html</link><dc:creator>瑞</dc:creator><author>瑞</author><pubDate>Wed, 20 Apr 2005 08:36:00 GMT</pubDate><guid>http://www.blogjava.net/ruey/archive/2005/04/20/3540.html</guid><wfw:comment>http://www.blogjava.net/ruey/comments/3540.html</wfw:comment><comments>http://www.blogjava.net/ruey/archive/2005/04/20/3540.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ruey/comments/commentRss/3540.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ruey/services/trackbacks/3540.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">JDBCExp.java</SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">import java.sql.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>import java.awt.</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000"> JdbcExp <BR><IMG id=Codehighlighter1_77_972_Open_Image onclick="this.style.display='none'; Codehighlighter1_77_972_Open_Text.style.display='none'; Codehighlighter1_77_972_Closed_Image.style.display='inline'; Codehighlighter1_77_972_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_77_972_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_77_972_Closed_Text.style.display='none'; Codehighlighter1_77_972_Open_Image.style.display='inline'; Codehighlighter1_77_972_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_77_972_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_77_972_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000"> main(String args[])<BR><IMG id=Codehighlighter1_120_970_Open_Image onclick="this.style.display='none'; Codehighlighter1_120_970_Open_Text.style.display='none'; Codehighlighter1_120_970_Closed_Image.style.display='inline'; Codehighlighter1_120_970_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_120_970_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_120_970_Closed_Text.style.display='none'; Codehighlighter1_120_970_Open_Image.style.display='inline'; Codehighlighter1_120_970_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_120_970_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_120_970_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> String url</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">jdbc:odbc:jbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> Connection con</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> Statement sm</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> ResultSet rs</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_227_316_Open_Image onclick="this.style.display='none'; Codehighlighter1_227_316_Open_Text.style.display='none'; Codehighlighter1_227_316_Closed_Image.style.display='inline'; Codehighlighter1_227_316_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_227_316_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_227_316_Closed_Text.style.display='none'; Codehighlighter1_227_316_Open_Image.style.display='inline'; Codehighlighter1_227_316_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_227_316_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_227_316_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> Class.forName(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">com.ms.jdbc.odbc.JdbcOdbcDriver</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">sun.jdbc.odbc.JdbcOdbcDriver </SPAN><SPAN style="COLOR: #008000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000"> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(Exception e)<BR><IMG id=Codehighlighter1_341_423_Open_Image onclick="this.style.display='none'; Codehighlighter1_341_423_Open_Text.style.display='none'; Codehighlighter1_341_423_Closed_Image.style.display='inline'; Codehighlighter1_341_423_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_341_423_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_341_423_Closed_Text.style.display='none'; Codehighlighter1_341_423_Open_Image.style.display='inline'; Codehighlighter1_341_423_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_341_423_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_341_423_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Can NOT load the JDBC-ODBC Bridge Driver</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">;<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_433_827_Open_Image onclick="this.style.display='none'; Codehighlighter1_433_827_Open_Text.style.display='none'; Codehighlighter1_433_827_Closed_Image.style.display='inline'; Codehighlighter1_433_827_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_433_827_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_433_827_Closed_Text.style.display='none'; Codehighlighter1_433_827_Open_Image.style.display='inline'; Codehighlighter1_433_827_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_433_827_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_433_827_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> con</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">DriverManager.getConnection(url);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> sm</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">con.createStatement();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> rs</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">sm.executeQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">select * from jbook</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">The result are followed: </SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">(rs.next())<BR><IMG id=Codehighlighter1_626_823_Open_Image onclick="this.style.display='none'; Codehighlighter1_626_823_Open_Text.style.display='none'; Codehighlighter1_626_823_Closed_Image.style.display='inline'; Codehighlighter1_626_823_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_626_823_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_626_823_Closed_Text.style.display='none'; Codehighlighter1_626_823_Open_Image.style.display='inline'; Codehighlighter1_626_823_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_626_823_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_626_823_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Index=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">rs.getInt(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">BookID=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">rs.getInt(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Title=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">rs.getString(</SPAN><SPAN style="COLOR: #000000">3</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> System.</SPAN><SPAN style="COLOR: #0000ff">out</SPAN><SPAN style="COLOR: #000000">.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Date=</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">rs.getTime(</SPAN><SPAN style="COLOR: #000000">4</SPAN><SPAN style="COLOR: #000000">));<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_852_853_Open_Image onclick="this.style.display='none'; Codehighlighter1_852_853_Open_Text.style.display='none'; Codehighlighter1_852_853_Closed_Image.style.display='inline'; Codehighlighter1_852_853_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_852_853_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_852_853_Closed_Text.style.display='none'; Codehighlighter1_852_853_Open_Image.style.display='inline'; Codehighlighter1_852_853_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(SQLException e)</SPAN><SPAN id=Codehighlighter1_852_853_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_852_853_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">finally</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_867_967_Open_Image onclick="this.style.display='none'; Codehighlighter1_867_967_Open_Text.style.display='none'; Codehighlighter1_867_967_Closed_Image.style.display='inline'; Codehighlighter1_867_967_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_867_967_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_867_967_Closed_Text.style.display='none'; Codehighlighter1_867_967_Open_Image.style.display='inline'; Codehighlighter1_867_967_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_867_967_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_867_967_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000"><BR><IMG id=Codehighlighter1_879_933_Open_Image onclick="this.style.display='none'; Codehighlighter1_879_933_Open_Text.style.display='none'; Codehighlighter1_879_933_Closed_Image.style.display='inline'; Codehighlighter1_879_933_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_879_933_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_879_933_Closed_Text.style.display='none'; Codehighlighter1_879_933_Open_Image.style.display='inline'; Codehighlighter1_879_933_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN id=Codehighlighter1_879_933_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_879_933_Open_Text><SPAN style="COLOR: #000000">{<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> rs.close();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> sm.close();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top> con.close();<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"> <BR><IMG id=Codehighlighter1_962_963_Open_Image onclick="this.style.display='none'; Codehighlighter1_962_963_Open_Text.style.display='none'; Codehighlighter1_962_963_Closed_Image.style.display='inline'; Codehighlighter1_962_963_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_962_963_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_962_963_Closed_Text.style.display='none'; Codehighlighter1_962_963_Open_Image.style.display='inline'; Codehighlighter1_962_963_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top> </SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(SQLException e)</SPAN><SPAN id=Codehighlighter1_962_963_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_962_963_Open_Text><SPAN style="COLOR: #000000">{}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top> }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV></DIV>1.建立数据源<BR>这里所建的数据源是指建立ODBC数据源,这点并不是JDBC要求,而是ODBC的要求所必须的.当使用JDBC-ODBC桥来建立连接是,必须先建立ODBC数据源.<BR>2.装入JDBC程序<BR>要使用JDBC访问数据库,首先必须加载JDBC驱动程序.只需一句代码.如果你的class name 是jdbc.DriverXYZ,那么你就把代码写成:Class.forName("jdbc.DriverXYZ");对于JDBC-ODBC桥来说,如果他的class name 是sun.jdbc.odbc.JdbcOdbcDriver,实际代码就可以写成:Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<BR>当然,在不同的环境中,驱动程序的类可能包含在不同的包里,比如在visual J++6.0中,JDBC-ODBC桥的驱动程序就包含在com.ms.jdbc.odbc包中,因此,其代码就写成了:Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");<BR>3.建立连接<BR>建立连接的标准方法是调用方法DriverManager.getConnection(String url,String user,String password).DriverManager类用于处理驱动程序的调如并且对新的数据库连接提供支持,它位于JDBC的管理层,通过该类,能够连接到URL表示的数据库的驱动程序.JDBC URL的标准语法是:jdbc:<subprotocol><subname>,其中subprotocol说明了使用哪种JDBC驱动程序,比如若使用的是JDBC-ODBC桥,就写为"odbc",若使用的是Sybase的JDBC驱动程序,就写"Sybase";subname则为驱动程序提供了连接数据库所需要的一切信息,比如jdbc:Sybase://jdbcstudy:4233/db_books,表示使用Sybase JDBC驱动程序,且连接安装在名为jdbcstudy的服务器的4233端口的db_books数据库中.对于JDBC-ODBC桥来说,subname就是数据源名.<BR>为了存取数据,还需要提供用户名和口令.例如:<BR>String url="jdbc:odbc:source";<BR>Connection con=DriverManager.getConnection(url,"user","password");<BR>4.执行SQL语句<BR>建立连接后,就能够向数据库发送SQL语句了.JDBC提供了Statement类来发送SQL语句,Statement类的对象用createStatement方法创建;SQL语句发送后,返回的结果通常存放在一个ResultSet类的对象中,ResultSet可以看做是一个表,这个表包含由SQL返回的列名和相应的值,ResultSet对象中维持了一个指向当前行的指针,通过一系列的getXXX方法,可以检索当前行的各个列,并显示出来.<BR>5.检索结果<BR>对Result对象进行处理后,才能将查询结果显示给用户.Result对象包括一个由查询语句返回的一个表ResultSet,这个表中包含了所有的查询结果.对Result对象的处理必须逐行进行,ResultSet.next()方法使指针下移一行.而对每一行中的各个列,则可以按任何顺序进行处理.Result类的getXXX方法可将结果集中的SQL数据类型转换为Java数据类型,如getInt,getString,getTime.<BR>6关闭连接<BR>在对象使用完毕后,应当关闭连接.<BR><img src ="http://www.blogjava.net/ruey/aggbug/3540.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ruey/" target="_blank">瑞</a> 2005-04-20 16:36 <a href="http://www.blogjava.net/ruey/archive/2005/04/20/3540.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>