﻿<?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-永远的船长</title><link>http://www.blogjava.net/buaacaptain/</link><description>只有偏执狂才能生存</description><language>zh-cn</language><lastBuildDate>Sat, 02 May 2026 23:46:50 GMT</lastBuildDate><pubDate>Sat, 02 May 2026 23:46:50 GMT</pubDate><ttl>60</ttl><item><title>也来介绍一下 extremeTable </title><link>http://www.blogjava.net/buaacaptain/archive/2006/12/07/86096.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Thu, 07 Dec 2006 07:19:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/12/07/86096.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/86096.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/12/07/86096.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/86096.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/86096.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1、何为 extremeTable，又一个开源taglib      extremeTable,开源的jsp 自定义标签,以表格的形式显示数据，当前最新版本为　1.0.1-M1.它是一个类似display tag,valueList 等开源产品.homepage: http://extremecomponents.org/download: http://sourceforge.net/proje...&nbsp;&nbsp;<a href='http://www.blogjava.net/buaacaptain/archive/2006/12/07/86096.html'>阅读全文</a><img src ="http://www.blogjava.net/buaacaptain/aggbug/86096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-12-07 15:19 <a href="http://www.blogjava.net/buaacaptain/archive/2006/12/07/86096.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一步一步教你远程调用EJB</title><link>http://www.blogjava.net/buaacaptain/archive/2006/09/09/68706.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Sat, 09 Sep 2006 05:48:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/09/09/68706.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/68706.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/09/09/68706.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/68706.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/68706.html</trackback:ping><description><![CDATA[
		<span id="ArticleContent1_ArticleContent1_lblContent"> 
<p>前期准备：弄清楚weblogic（或jboss）、tomcat、JBluder（或eclipse＋MyEclipse）的使用方法，能写一个简单的基于struts框架的web工程，然后准备两台联网的电脑（局域网也可以），如果没有条件，也可以在同一台电脑上分别安装两个web服务器（例如：weblogic和tomcat）来代替，本文将采用后一种方法，采用weblogic作EJB容器，tomcat作web容器，用struts工程来调用EJB</p><p>准备好了吗？让我们开始下一步</p><p>第一步：写一个简单的EJB。写EJB最好用的还是JBuilder，毕竟够傻瓜化。当然作为专业人士，eclipse搭配MyEclipse是最佳选择，不过作为初学者，建议采用JBuilder。以下是本文测试所用到的EJB。</p><p>remote接口：</p><p>package testhello;</p><p>import javax.ejb.EJBObject;</p><p>public interface SayHello extends EJBObject {<br />    public String sayHello(String name) throws java.rmi.RemoteException;<br />}<br /></p><p>home接口：</p><p>package testhello;</p><p>import javax.ejb.EJBHome;<br />import javax.ejb.CreateException;<br />import java.rmi.RemoteException;</p><p>public interface SayHelloHome extends EJBHome {<br />    public SayHello create() throws CreateException, RemoteException;<br />}<br /></p><p>bean类：</p><p>package testhello;</p><p>import javax.ejb.SessionBean;<br />import javax.ejb.SessionContext;<br />import javax.ejb.CreateException;</p><p>public class SayHelloBean implements SessionBean {<br />    SessionContext sessionContext;<br />    public void ejbCreate() throws CreateException {<br />    }</p><p>    public void ejbRemove() {<br />    }</p><p>    public void ejbActivate() {<br />    }</p><p>    public void ejbPassivate() {<br />    }</p><p><br />    public void setSessionContext(SessionContext sessionContext) {<br />        this.sessionContext = sessionContext;<br />    }</p><p>    public String  sayHello(String name) {<br />        return "Hello "+name;<br />    }<br />}<br /></p><p>如果你是采用上面两种工具来写的话，配置文件就不必考虑了</p><p>第二步：利用JBuilder或eclipse将这个EJB工程编译并打包，会得到一个jar(如果你的工程名叫testhello，那么这个jar文件就是testhello.jar)文件。如果你的EJB容器（weblogic或JBoss）是在本机上，那么在JBuilder或eclipse中就可以直接鼠标右击EJB工程，来部署EJB。如果需要部署到远程服务器上，只需要通过EJB容器的控制台将testhello.jar上传到远程端，然后在EJB Modler里面按提示部署好EJB。最后，别忘了在JNDI Tree里面察看你的EJB工程的JNDI名，本例的JNDI名叫SayHello</p><p>第三步：将remote接口和home接口打包成jar文件，copy到你要远程调用EJB的struts工程下的lib目录（例如：helloapp -&gt;WEB-INF -&gt;lib）</p><p>第四步：将weblogic的weblogic.jar（在weblogic的安装目录－&gt;weblogic81－&gt;server－&gt;lib文件夹中）copy到tomcat安装目录下的－&gt;shared－&gt;lib文件夹中，其实这里我们需要用到的只是weblogic.jar里的几个class文件而已，不过对于初学者而言，先不必去深究到底只需要那几个class。</p><p>第五步：编写一个简单的struts工程（其实这些都可以用工具生成），一下是调用EJB的HelloAction的源代码(特别要注意的是，记得要将之前第三步生成的jar包导入编辑器中，否则下面的代码编译通不过。如果你不知道导入jar包，就把那个jar包多copy一份到你的jdk安装目录 -&gt; jre-&gt; lib-&gt; ext文件夹下)</p><p>package logging.actions;<br />import logging.Constants;</p><p>import java.util.*;<br />import javax.servlet.ServletException;<br />import javax.servlet.RequestDispatcher;<br />import javax.servlet.http.HttpSession;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br />import javax.naming.Context;<br />import javax.naming.InitialContext;<br />import javax.naming.NamingException;<br />import javax.rmi.PortableRemoteObject;</p><p>import org.apache.struts.action.Action;<br />import org.apache.struts.action.ActionForm;<br />import org.apache.struts.action.ActionForward;<br />import org.apache.struts.action.ActionMapping;<br />import org.apache.struts.action.ActionMessage;<br />import org.apache.struts.action.ActionMessages;<br />import org.apache.struts.util.MessageResources;<br />import org.apache.struts.validator.DynaValidatorForm;</p><p>public final class HelloAction extends Action{<br /> <br /> public ActionForward execute(ActionMapping mapping,<br />         ActionForm form,<br />         HttpServletRequest request,<br />         HttpServletResponse response)<br /> throws Exception{</p><p>        InitialContext ctx=this.getInitialContext();</p><p>  //查找JNDI名为SayHello的EJB组件<br />        Object obj=ctx.lookup("SayHello");</p><p><br />  //获得远程EJB组件的home接口的引用<br />        testhello.SayHelloHome home=(testhello.SayHelloHome)PortableRemoteObject.narrow(obj,testhello.SayHelloHome.class);</p><p><br />  //获得远程EJB组件的remote接口的引用<br />        testhello.SayHello hello=home.create();<br />        <br />        String name="飘然随风";<br />        String sayString=hello.sayHello(name);<br />        <br />        request.setAttribute("userName",name);<br />        request.setAttribute("passWord",sayString);<br />        request.removeAttribute(mapping.getAttribute());<br />       <br />  return mapping.findForward("loginSuccess");<br /> }<br /> </p><p>/*以下方法是作用是：通过传递环境属性选择JNDI驱动和服务器的网络位置，<br />  并连接到连接到JNDI树。<br />  这是采用weblogic做EJB容器时，远程调用EJB的固定初始化模式，初学者可以死记下来<br />*/<br /> private  InitialContext getInitialContext() throws Exception {<br />  //EJB容器的地址<br />     String url = "t3://image:7001";<br />     String user = null;<br />     String password = null;<br />     Properties properties;<br />  <br />        properties = new Properties();<br />        properties.put(Context.INITIAL_CONTEXT_FACTORY,<br />                       "weblogic.jndi.WLInitialContextFactory");<br />        properties.put(Context.PROVIDER_URL, url);<br />        if (user != null) {<br />            properties.put(Context.SECURITY_PRINCIPAL, user);<br />            properties.put(Context.SECURITY_CREDENTIALS,<br />                           password == null ? "" : password);<br />        }<br />        return new javax.naming.InitialContext(properties);<br /> }<br />}</p><p>第六步：如果你严格按照上面的步骤做了，那么剩下的就是同时启动weblogic和tomcat来测试了。</p></span>
<img src ="http://www.blogjava.net/buaacaptain/aggbug/68706.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-09-09 13:48 <a href="http://www.blogjava.net/buaacaptain/archive/2006/09/09/68706.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>深入 Lucene 索引机制</title><link>http://www.blogjava.net/buaacaptain/archive/2006/08/01/61256.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Tue, 01 Aug 2006 15:12:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/08/01/61256.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/61256.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/08/01/61256.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/61256.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/61256.html</trackback:ping><description><![CDATA[
		<blockquote>
				<p>Lucene 是一个基于 Java 的全文检索工具包，你可以利用它来为你的应用程序加入索引和检索功能。Lucene 目前是著名的 Apache Jakarta 家族中的一个开源项目，下面我们即将学习 Lucene 的索引机制以及它的索引文件的结构。</p>
				<p>在这篇文章中，我们首先演示如何使用 Lucene 来索引文档，接着讨论如何提高索引的性能。最后我们来分析 Lucene 的索引文件结构。需要记住的是，Lucene 不是一个完整的应用程序，而是一个信息检索包，它方便你为你的应用程序添加索引和搜索功能。</p>
		</blockquote>
		<!--START RESERVED FOR FUTURE USE INCLUDE FILES-->
		<!-- include java script once we verify teams wants to use this and it will work on dbcs and cyrillic characters -->
		<!--END RESERVED FOR FUTURE USE INCLUDE FILES-->
		<p>
				<a name="N10047">
						<span class="atitle">
								<font face="Arial" size="4">架构概览</font>
						</span>
				</a>
		</p>
		<p>图一显示了 Lucene 的索引机制的架构。Lucene 使用各种解析器对各种不同类型的文档进行解析。比如对于 HTML 文档，HTML 解析器会做一些预处理的工作，比如过滤文档中的 HTML 标签等等。HTML 解析器的输出的是文本内容，接着 Lucene 的分词器(Analyzer)从文本内容中提取出索引项以及相关信息，比如索引项的出现频率。接着 Lucene 的分词器把这些信息写到索引文件中。</p>
		<br />
		<a name="N10052">
				<b>图一：Lucene 索引机制架构</b>
		</a>
		<br />
		<img height="345" alt="图一：Lucene 索引机制架构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/image002.jpg" width="438" border="0" />
		<br />
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10062">
						<span class="atitle">
								<font face="Arial" size="4">用Lucene索引文档</font>
						</span>
				</a>
		</p>
		<p>接下来我将一步一步的来演示如何利用 Lucene 为你的文档创建索引。只要你能将要索引的文件转化成文本格式，Lucene 就能为你的文档建立索引。比如，如果你想为 HTML 文档或者 PDF 文档建立索引，那么首先你就需要从这些文档中提取出文本信息，然后把文本信息交给 Lucene 建立索引。我们接下来的例子用来演示如何利用 Lucene 为后缀名为 txt 的文件建立索引。</p>
		<p>1． 准备文本文件</p>
		<p>首先把一些以 txt 为后缀名的文本文件放到一个目录中，比如在 Windows 平台上，你可以放到 C:\\files_to_index 下面。</p>
		<p>2． 创建索引</p>
		<p>清单1是为我们所准备的文档创建索引的代码。</p>
		<br />
		<a name="N10077">
				<b>清单1：用 Lucene 索引你的文档</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">package lucene.index;

import java.io.File;
import java.io.FileReader;
import java.io.Reader;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

/**
 * This class demonstrates the process of creating an index with Lucene 
 * for text files in a directory.
 */
public class TextFileIndexer {
 public static void main(String[] args) throws Exception{
   //fileDir is the directory that contains the text files to be indexed
   File   fileDir  = new File("C:\\files_to_index ");

   //indexDir is the directory that hosts Lucene's index files
   File   indexDir = new File("C:\\luceneIndex");
   Analyzer luceneAnalyzer = new StandardAnalyzer();
   IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
   File[] textFiles  = fileDir.listFiles();
   long startTime = new Date().getTime();

   //Add documents to the index
   for(int i = 0; i &lt; textFiles.length; i++){
     if(textFiles[i].isFile() &gt;&gt; textFiles[i].getName().endsWith(".txt")){
       System.out.println("File " + textFiles[i].getCanonicalPath() 
              + " is being indexed");
       Reader textReader = new FileReader(textFiles[i]);
       Document document = new Document();
       document.add(Field.Text("content",textReader));
       document.add(Field.Text("path",textFiles[i].getPath()));
       indexWriter.addDocument(document);
     }
   }

   indexWriter.optimize();
   indexWriter.close();
   long endTime = new Date().getTime();

   System.out.println("It took " + (endTime - startTime) 
              + " milliseconds to create an index for the files in the directory "
              + fileDir.getPath());
  }
}
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>正如清单1所示，你可以利用 Lucene 非常方便的为文档创建索引。接下来我们分析一下清单1中的比较关键的代码，我们先从下面的一条语句开始看起。</p>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">Analyzer luceneAnalyzer = new StandardAnalyzer();
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这条语句创建了类 StandardAnalyzer 的一个实例，这个类是用来从文本中提取出索引项的。它只是抽象类 Analyzer 的其中一个实现。Analyzer 也有一些其它的子类，比如 SimpleAnalyzer 等。</p>
		<p>我们接着看另外一条语句：</p>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这条语句创建了类 IndexWriter 的一个实例，该类也是 Lucene 索引机制里面的一个关键类。这个类能创建一个新的索引或者打开一个已存在的索引并为该所引添加文档。我们注意到该类的构造函数接受三个参数，第一个参数指定了存储索引文件的路径。第二个参数指定了在索引过程中使用什么样的分词器。最后一个参数是个布尔变量，如果值为真，那么就表示要创建一个新的索引，如果值为假，就表示打开一个已经存在的索引。</p>
		<p>接下来的代码演示了如何添加一个文档到索引文件中。</p>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">Document document = new Document();
document.add(Field.Text("content",textReader));
document.add(Field.Text("path",textFiles[i].getPath()));
indexWriter.addDocument(document);
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>首先第一行创建了类 Document 的一个实例，它由一个或者多个的域(Field)组成。你可以把这个类想象成代表了一个实际的文档，比如一个 HTML 页面，一个 PDF 文档，或者一个文本文件。而类 Document 中的域一般就是实际文档的一些属性。比如对于一个 HTML 页面，它的域可能包括标题，内容，URL 等。我们可以用不同类型的 Field 来控制文档的哪些内容应该索引，哪些内容应该存储。如果想获取更多的关于 Lucene 的域的信息，可以参考 Lucene 的帮助文档。代码的第二行和第三行为文档添加了两个域，每个域包含两个属性，分别是域的名字和域的内容。在我们的例子中两个域的名字分别是"content"和"path"。分别存储了我们需要索引的文本文件的内容和路径。最后一行把准备好的文档添加到了索引当中。</p>
		<p>当我们把文档添加到索引中后，不要忘记关闭索引，这样才保证 Lucene 把添加的文档写回到硬盘上。下面的一句代码演示了如何关闭索引。</p>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">indexWriter.close();
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>利用清单1中的代码，你就可以成功的将文本文档添加到索引中去。接下来我们看看对索引进行的另外一种重要的操作，从索引中删除文档。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N100BD">
						<span class="atitle">
								<font face="Arial" size="4">从索引中删除文档</font>
						</span>
				</a>
		</p>
		<p>类IndexReader负责从一个已经存在的索引中删除文档，如清单2所示。</p>
		<br />
		<a name="N100C6">
				<b>清单2：从索引中删除文档</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">File   indexDir = new File("C:\\luceneIndex");
IndexReader ir = IndexReader.open(indexDir);
ir.delete(1);
ir.delete(new Term("path","C:\\file_to_index\lucene.txt"));
ir.close();
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>在清单2中，第二行用静态方法 IndexReader.open(indexDir) 初始化了类 IndexReader 的一个实例，这个方法的参数指定了索引的存储路径。类 IndexReader 提供了两种方法去删除一个文档，如程序中的第三行和第四行所示。第三行利用文档的编号来删除文档。每个文档都有一个系统自动生成的编号。第四行删除了路径为"C:\\file_to_index\lucene.txt"的文档。你可以通过指定文件路径来方便的删除一个文档。值得注意的是虽然利用上述代码删除文档使得该文档不能被检索到，但是并没有物理上删除该文档。Lucene 只是通过一个后缀名为 .delete 的文件来标记哪些文档已经被删除。既然没有物理上删除，我们可以方便的把这些标记为删除的文档恢复过来，如清单 3 所示，首先打开一个索引，然后调用方法 ir.undeleteAll() 来完成恢复工作。</p>
		<br />
		<a name="N100D3">
				<b>清单3：恢复已删除文档</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">File   indexDir = new File("C:\\luceneIndex");
IndexReader ir = IndexReader.open(indexDir);
ir.undeleteAll();
ir.close();
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>你现在也许想知道如何物理上删除索引中的文档，方法也非常简单。清单 4 演示了这个过程。</p>
		<br />
		<a name="N100E0">
				<b>清单4：如何物理上删除文档</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">File   indexDir = new File("C:\\luceneIndex");
Analyzer luceneAnalyzer = new StandardAnalyzer();
IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,false);
indexWriter.optimize();
indexWriter.close();
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>在清单 4 中，第三行创建了类 IndexWriter 的一个实例，并且打开了一个已经存在的索引。第 4 行对索引进行清理，清理过程中将把所有标记为删除的文档物理删除。</p>
		<p>Lucene 没有直接提供方法对文档进行更新，如果你需要更新一个文档，那么你首先需要把这个文档从索引中删除，然后把新版本的文档加入到索引中去。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N100F0">
						<span class="atitle">
								<font face="Arial" size="4">提高索引性能</font>
						</span>
				</a>
		</p>
		<p>利用 Lucene，在创建索引的工程中你可以充分利用机器的硬件资源来提高索引的效率。当你需要索引大量的文件时，你会注意到索引过程的瓶颈是在往磁盘上写索引文件的过程中。为了解决这个问题, Lucene 在内存中持有一块缓冲区。但我们如何控制 Lucene 的缓冲区呢？幸运的是，Lucene 的类 IndexWriter 提供了三个参数用来调整缓冲区的大小以及往磁盘上写索引文件的频率。</p>
		<p>1．合并因子（mergeFactor）</p>
		<p>这个参数决定了在 Lucene 的一个索引块中可以存放多少文档以及把磁盘上的索引块合并成一个大的索引块的频率。比如，如果合并因子的值是 10，那么当内存中的文档数达到 10 的时候所有的文档都必须写到磁盘上的一个新的索引块中。并且，如果磁盘上的索引块的隔数达到 10 的话，这 10 个索引块会被合并成一个新的索引块。这个参数的默认值是 10，如果需要索引的文档数非常多的话这个值将是非常不合适的。对批处理的索引来讲，为这个参数赋一个比较大的值会得到比较好的索引效果。</p>
		<p>2．最小合并文档数</p>
		<p>这个参数也会影响索引的性能。它决定了内存中的文档数至少达到多少才能将它们写回磁盘。这个参数的默认值是10，如果你有足够的内存，那么将这个值尽量设的比较大一些将会显著的提高索引性能。</p>
		<p>3．最大合并文档数</p>
		<p>这个参数决定了一个索引块中的最大的文档数。它的默认值是 Integer.MAX_VALUE，将这个参数设置为比较大的值可以提高索引效率和检索速度，由于该参数的默认值是整型的最大值，所以我们一般不需要改动这个参数。</p>
		<p>清单 5 列出了这个三个参数用法，清单 5 和清单 1 非常相似，除了清单 5 中会设置刚才提到的三个参数。</p>
		<br />
		<a name="N1010E">
				<b>清单5：提高索引性能</b>
		</a>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">/**
 * This class demonstrates how to improve the indexing performance 
 * by adjusting the parameters provided by IndexWriter.
 */
public class AdvancedTextFileIndexer  {
  public static void main(String[] args) throws Exception{
    //fileDir is the directory that contains the text files to be indexed
    File   fileDir  = new File("C:\\files_to_index");

    //indexDir is the directory that hosts Lucene's index files
    File   indexDir = new File("C:\\luceneIndex");
    Analyzer luceneAnalyzer = new StandardAnalyzer();
    File[] textFiles  = fileDir.listFiles();
    long startTime = new Date().getTime();

    int mergeFactor = 10;
    int minMergeDocs = 10;
    int maxMergeDocs = Integer.MAX_VALUE;
    IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);        
    indexWriter.mergeFactor = mergeFactor;
    indexWriter.minMergeDocs = minMergeDocs;
    indexWriter.maxMergeDocs = maxMergeDocs;

    //Add documents to the index
    for(int i = 0; i &lt; textFiles.length; i++){
      if(textFiles[i].isFile() &gt;&gt; textFiles[i].getName().endsWith(".txt")){
        Reader textReader = new FileReader(textFiles[i]);
        Document document = new Document();
        document.add(Field.Text("content",textReader));
        document.add(Field.Keyword("path",textFiles[i].getPath()));
        indexWriter.addDocument(document);
      }
    }

    indexWriter.optimize();
    indexWriter.close();
    long endTime = new Date().getTime();

    System.out.println("MergeFactor: " + indexWriter.mergeFactor);
    System.out.println("MinMergeDocs: " + indexWriter.minMergeDocs);
    System.out.println("MaxMergeDocs: " + indexWriter.maxMergeDocs);
    System.out.println("Document number: " + textFiles.length);
    System.out.println("Time consumed: " + (endTime - startTime) + " milliseconds");
  }
}
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>通过这个例子，我们注意到在调整缓冲区的大小以及写磁盘的频率上面 Lucene 给我们提供了非常大的灵活性。现在我们来看一下代码中的关键语句。如下的代码首先创建了类 IndexWriter 的一个实例，然后对它的三个参数进行赋值。</p>
		<br />
		<table cellspacing="0" cellpadding="5" width="100%" bgcolor="#eeeeee" border="1">
				<tbody>
						<tr>
								<td>
										<code>
												<pre class="section">int mergeFactor = 10;
int minMergeDocs = 10;
int maxMergeDocs = Integer.MAX_VALUE;
IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);        
indexWriter.mergeFactor = mergeFactor;
indexWriter.minMergeDocs = minMergeDocs;
indexWriter.maxMergeDocs = maxMergeDocs;
</pre>
										</code>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>下面我们来看一下这三个参数取不同的值对索引时间的影响，注意参数值的不同和索引之间的关系。我们为这个实验准备了 10000 个测试文档。表 1 显示了测试结果。</p>
		<br />
		<a name="N10129">
				<b>表1：测试结果</b>
		</a>
		<br />
		<img height="199" alt="表1：测试结果" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table1.gif" width="502" border="0" />
		<br />
		<p>通过表 1，你可以清楚地看到三个参数对索引时间的影响。在实践中，你会经常的改变合并因子和最小合并文档数的值来提高索引性能。只要你有足够大的内存，你可以为合并因子和最小合并文档数这两个参数赋尽量大的值以提高索引效率，另外我们一般无需更改最大合并文档数这个参数的值，因为系统已经默认将它设置成了最大。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N1013C">
						<span class="atitle">
								<font face="Arial" size="4">Lucene 索引文件结构分析</font>
						</span>
				</a>
		</p>
		<p>在分析 Lucene 的索引文件结构之前，我们先要理解反向索引（Inverted index）这个概念，反向索引是一种以索引项为中心来组织文档的方式，每个索引项指向一个文档序列，这个序列中的文档都包含该索引项。相反，在正向索引中，文档占据了中心的位置，每个文档指向了一个它所包含的索引项的序列。你可以利用反向索引轻松的找到那些文档包含了特定的索引项。Lucene正是使用了反向索引作为其基本的索引结构。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10145">
						<span class="atitle">
								<font face="Arial" size="4">索引文件的逻辑视图</font>
						</span>
				</a>
		</p>
		<p>在Lucene 中有索引块的概念，每个索引块包含了一定数目的文档。我们能够对单独的索引块进行检索。图 2 显示了 Lucene 索引结构的逻辑视图。索引块的个数由索引的文档的总数以及每个索引块所能包含的最大文档数来决定。</p>
		<br />
		<a name="N10150">
				<b>图2：索引文件的逻辑视图</b>
		</a>
		<br />
		<img height="415" alt="图2：索引文件的逻辑视图" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/image004.jpg" width="467" border="0" />
		<br />
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N10160">
						<span class="atitle">
								<font face="Arial" size="4">Lucene 中的关键索引文件</font>
						</span>
				</a>
		</p>
		<p>下面的部分将会分析Lucene中的主要的索引文件，可能分析有些索引文件的时候没有包含文件的所有的字段，但不会影响到对索引文件的理解。</p>
		<p>1．索引块文件</p>
		<p>这个文件包含了索引中的索引块信息，这个文件包含了每个索引块的名字以及大小等信息。表 2 显示了这个文件的结构信息。</p>
		<br />
		<a name="N10171">
				<b>表2：索引块文件结构</b>
		</a>
		<br />
		<img height="198" alt="表2：索引块文件结构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table2.gif" width="568" border="0" />
		<br />
		<p>2．域信息文件</p>
		<p>我们知道，索引中的文档由一个或者多个域组成，这个文件包含了每个索引块中的域的信息。表 3 显示了这个文件的结构。</p>
		<br />
		<a name="N10189">
				<b>表3：域信息文件结构</b>
		</a>
		<br />
		<img height="179" alt="表3：域信息文件结构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table3.gif" width="567" border="0" />
		<br />
		<p>3．索引项信息文件</p>
		<p>这是索引文件里面最核心的一个文件，它存储了所有的索引项的值以及相关信息，并且以索引项来排序。表 4 显示了这个文件的结构。</p>
		<br />
		<a name="N101A1">
				<b>表4：索引项信息文件结构</b>
		</a>
		<br />
		<img height="252" alt="表4：索引项信息文件结构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table4.gif" width="568" border="0" />
		<br />
		<p>4．频率文件</p>
		<p>这个文件包含了包含索引项的文档的列表，以及索引项在每个文档中出现的频率信息。如果Lucene在索引项信息文件中发现有索引项和搜索词相匹配。那么 Lucene 就会在频率文件中找有哪些文件包含了该索引项。表5显示了这个文件的一个大致的结构，并没有包含这个文件的所有字段。</p>
		<br />
		<a name="N101B9">
				<b>表5：频率文件的结构</b>
		</a>
		<br />
		<img height="124" alt="表5：频率文件的结构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table5.gif" width="567" border="0" />
		<br />
		<p>5．位置文件</p>
		<p>这个文件包含了索引项在每个文档中出现的位置信息，你可以利用这些信息来参与对索引结果的排序。表 6 显示了这个文件的结构</p>
		<br />
		<a name="N101D1">
				<b>表6：位置文件的结构</b>
		</a>
		<br />
		<img height="69" alt="表6：位置文件的结构" src="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/images/table6.gif" width="568" border="0" />
		<br />
		<p>到目前为止我们介绍了 Lucene 中的主要的索引文件结构，希望能对你理解 Lucene 的物理的存储结构有所帮助。</p>
		<br />
		<table cellspacing="0" cellpadding="0" width="100%" border="0">
				<tbody>
						<tr>
								<td>
										<img height="1" alt="" src="http://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" />
										<br />
										<img height="6" alt="" src="http://www.ibm.com/i/c.gif" width="8" border="0" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" cellspacing="0" cellpadding="0" align="right">
				<tbody>
						<tr align="right">
								<td>
										<img height="4" alt="" src="http://www.ibm.com/i/c.gif" width="100%" />
										<br />
										<table cellspacing="0" cellpadding="0" border="0">
												<tbody>
														<tr>
																<td valign="center">
																		<img height="16" alt="" src="http://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" />
																		<br />
																</td>
																<td valign="top" align="right">
																		<a class="fbox" href="http://www-128.ibm.com/developerworks/cn/java/wa-lucene/index.html#main">
																				<b>
																						<font color="#996699">回页首</font>
																				</b>
																		</a>
																</td>
														</tr>
												</tbody>
										</table>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="N101E4">
						<span class="atitle">
								<font face="Arial" size="4">总结</font>
						</span>
				</a>
		</p>
		<p>目前已经有非常多的知名的组织正在使用 Lucene，比如，Lucene 为 Eclipse 的帮助系统，麻省理工学院的 OpenCourseWare 提供了搜索功能。通过阅读这篇文章，希望你能对 Lucene 的索引机制有所了解，并且你会发现利用 Lucene 创建索引是非常简单的事情。</p>
<img src ="http://www.blogjava.net/buaacaptain/aggbug/61256.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-08-01 23:12 <a href="http://www.blogjava.net/buaacaptain/archive/2006/08/01/61256.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xsl</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/30/60862.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Sun, 30 Jul 2006 06:57:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/30/60862.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/60862.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/30/60862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/60862.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/60862.html</trackback:ping><description><![CDATA[
		<a href="/rickhunter/articles/59742.html">http://www.blogjava.net/rickhunter/articles/59742.html</a>
		<br />
		<a href="http://www.blueidea.com/tech/web/2004/1798_4.asp">http://www.blueidea.com/tech/web/2004/1798_4.asp</a>
		<br />
		<br />　本期介绍多个XSL对于VBScript、JScript增加的方法、属性，以充分发挥XML的优势，用于&lt;xsl:script&gt;、&lt;xsl:eval&gt;标记内表达式的编写或&lt;xsl:if&gt;、&lt;xsl:when&gt;的expr属性。
<p></p><p>　　一、absoluteChildNumber </p><p>　　含义：返回结点相对于它所有的兄弟（不论名字是否相同）的序号。</p><p>　　语法：absoluteChildNumber(node)</p><p>　　参数：node ── 对象，欲返回编号的结点。</p><p>　　示例：</p><p>　　1、假定文档结构为：&lt;document&gt;&lt;head/&gt;&lt;body/&gt;&lt;/document&gt;，其中document为顶层结点，下述表达式将输出：</p><p>&lt;xsl:eval&gt;<br />absoluteChildNumber(this.selectNodes('/document/body').item(0))<br />&lt;/xsl:eval&gt;</p><p>　　2、确定当前结点相对于其所有兄弟的序号：</p><p>&lt;xsl:eval&gt;<br />absoluteChildNumber(this)<br />&lt;/xsl:eval&gt;</p><p>　　二、ancestorChildNumber</p><p>　　含义：从给定结点出发根据给定祖先结点名返回最近的祖先结点的序号（相对于同名结点）。如果找不祖先，则返回0。</p><p>　　语法：ancestorChildNumber(bstrNodeName, pNode)</p><p>　　参数：</p><p>　　bstrNodeName ── 字符串。被搜索的祖先结点的名字。</p><p>　　pNode ── 对象。搜索开始位置的结点。</p><p>　　示例查找当前结点最近的名为report祖先结点：</p><p>ancestorChildNumber('report',this)</p><p>　　三、attributes</p><p>　　含义：返回结点属性的集合。</p><p>　　语法：object.attributes</p><p>　　参数：object ── 结点对象。</p><p>　　示例：当前结点属性的个数</p><p>this.attributes.length</p><p>　　当前结点第三个属性的值</p><p>this.attributs.item(2).value</p><p>或<br /><br />this.attributes.item(2).text</p><p>或<br /><br />this.attributes(2).text</p><p>　　注意：如果给定的下标大于属性总和减1将出错，第一个属性的下标是0。</p><p>　　四、baseName</p><p>　　含义：返回有名字空间限制的基本名，即不包括名字前缀。</p><p>　　语法：object.baseName</p><p>　　参数：object ── 结点对象</p><p>　　示例，当前结点的基本名：<br /><br />this.baseName</p><p>　　五、childNumber</p><p>　　含义：返回结点相对于同名同胞的序号。</p><p>　　语法：childNumber(object)</p><p>　　参数：object ── 结点对象</p><p>　　示例，假定XML文档结构如下：</p><p>&lt;x&gt;&lt;y&gt;&lt;z&gt;&lt;/z&gt;&lt;/y&gt;&lt;/x&gt;</p><p>　　如果当前结点是z，则childNumber(this)返回1，而absoluteChildNumber(this)返回3。 </p><p>　　六、dataType</p><p>　　含义：设定或读取结点的数据类型。</p><p>　　语法：设定结点的数据类型 object.dataType=objValue<br />　　　　　读取结点的数据类型 objValue=object.dataType</p><p>　　参数：object ── 结点对象。<br /><br />　　示例，读取当前结点的数据类型：</p><p>dtType=this.dataType</p><p>　　七、depth</p><p>　　含义：指定结点出现在文档树上的深度，即该结点位于文档第几层，顶层结点位于第一层，根结点（即用"/"表示的结点）位于第0层。</p><p>　　语法：depth(pNode)</p><p>　　参数：pNode ── 结点对象</p><p>　　示例，当前结点的深度：</p><p>depth(this)</p><p>　　八、firstChild、lastChild</p><p>　　含义：返回结点的第一个子结点（或最后一个子结点）。</p><p>　　语法：pNode.firstChild<br />　　　　　pNode.lastChild</p><p>　　参数：pNode ── 结点对象</p><p>　　示例，当前结点的第一个结点的名字：</p><p>this.firstChild.nodeName</p><p>　　九、formatIndex</p><p>　　含义：用指定的计数系统格式化提供的整数。</p><p>　　语法：formatIndex(lIndex, bstrFormat)</p><p>　　参数：</p><p>　　lIndex ── 整型数值或变量</p><p>　　bstrFormat ── 数据格式，可选值有a、A、i、I、1、01（以0打头的数值形式，如果要求固定长度的编号如0001、0002则非常有用）。</p><p>　　示例，当前结点的大写罗马数字编号：</p><p>formatIndex(childNumber(this),'I')</p><p>　　十、formatNumber</p><p>　　含义：以指定格式输出数值。</p><p>　　语法：formatNumber(dblNumber, bstrFormat)</p><p>　　参数：说明同formatNumber，不同之处在于格式化的可以是小数。</p><p>　　示例，对变量a的值格式化为两位小数：<br /><br />formatNumber(a,'#.00')：</p><p>　　十一、hasChildNodes</p><p>　　含义：如果结点有子结点则返回true（-1），否则为false（0）。</p><p>　　语法：pNode.hasChildNodes()</p><p>　　注意：与此前介绍的函数不同，此函数后必须带一个空括号。</p><p>　　示例，判断当前结点是否有子结点：</p><p>this.hasChildNodes</p><p>　　十二、namespaceURI、prefix</p><p>　　含义：返回结点名字空间的全局资源标识符（或前缀）。</p><p>　　语法：pNode.namespaceURI<br />　　　　　pNode.prifix</p><p>　　十三、nextSibling、previousSibling、parentNode</p><p>　　含义：返回结点的下一个兄弟（或前一个兄弟、或结点的父结点）。</p><p>　　语法：pNode.nextSibling<br />　　　　　pNode.previousSibling<br />　　　　　pNode.parentNode</p><p>　　注意：对根结点（即"/"）应用parentNode方法、对第一个孩子结点应用previousSibling方法、对最后一个孩子结点应用nextSibling方法均会导致错误，可通过此过关系运算符==（等于）和!=（不等于）来判断一个结点是否某一指定结点，格式为pNode1 = pNode2或pNode2 != pNode2。</p><p>　　十四、nodeName</p><p>　　含义：返回元素、属性、入口的名字或其他类型结点的一个特定字符串。</p><p>　　语法：pNode.nodeName</p><p>　　示例，当前结点的名字：</p><p>this.nodeName</p><p>　　十五、nodeType、NodeTypeString</p><p>　　含义：返回结点的类型的数值形式（或字符串形式）。<br /><br />　　语法：pNode.nodeType 或 pNode.nodeTypeString</p><p>　　返回值：</p><table style="FONT-SIZE: 9pt" cellspacing="1" cellpadding="0" width="500" align="center" border="0"><tbody><tr><td width="209" bgcolor="#000000" height="25"><font color="#ffffff"> 结点类型</font></td><td width="85" bgcolor="#000000"><font color="#ffffff"> 结点类型值</font></td><td width="202" bgcolor="#000000"><font color="#ffffff"> 结点的字符形式描述</font></td></tr><tr><td width="209" bgcolor="#cccccc" height="25"> Element</td><td width="85" bgcolor="#cccccc"> 1</td><td width="202" bgcolor="#cccccc"> 'element'</td></tr><tr><td width="209" bgcolor="#eeeeee" height="25"> Element Attribute</td><td width="85" bgcolor="#eeeeee"> 2</td><td width="202" bgcolor="#eeeeee"> 'attribute'</td></tr><tr bgcolor="#cccccc"><td width="209" height="25"> Markup-Delimited Region of Text</td><td width="85"> 3</td><td width="202"> 'text'</td></tr><tr><td width="209" bgcolor="#eeeeee" height="25"> Processing Instruction</td><td width="85" bgcolor="#eeeeee"> 7</td><td width="202" bgcolor="#eeeeee"> 'processing_instruction'</td></tr><tr bgcolor="#cccccc"><td width="209" height="25"> Comment</td><td width="85"> 8</td><td width="202"> 'comment'</td></tr><tr><td width="209" bgcolor="#eeeeee" height="25"> Document Entity</td><td width="85" bgcolor="#eeeeee"> 9</td><td width="202" bgcolor="#eeeeee"> 'document'</td></tr></tbody></table><p>　　十六、nodeTypedValue</p><p>　　含义：以结点预定义的数据类型返回结点的值。</p><p>　　语法：pNode.nodeTypedValue</p><p>　　示例，假定当前结点的数据类型是fixed.14.4，下例将以数值返回结点的值，而不是文本一个字符串：</p><p>this.nodeTypedValue</p><p>　　十七、nodeValue</p><p>　　含义：返回结点的文本。</p><p>　　语法：pNode.nodeValue</p><p>　　注意：该方法不用于元素类结点，可用于属性、CDATA、注释、文本等结点。</p><p>　　示例，当前元素第一个属性的值：</p><p>this.attributes(0).nodeValue</p><p>　　当前元素内的文本（假定该元素内只有文本，无其它元素，即&lt;mark&gt;text&lt;/mark&gt;，建议多尝几次掌握其确切的用法）。</p><p>this.firstChild.nodeValue</p><p>　　十八、ownerDocument</p><p>　　含义：返回包含该结点的文档的根。</p><p>　　语法：pNode.ownerDocument</p><p>　　注意：该方法用于文档的根结点将出错。</p><p>　　十九、selectNodes</p><p>　　含义：给定的样式匹配应用于当前结点并返回匹配的结点集合。</p><p>　　语法：pNode.selectNodes('pattern')</p><p>　　提示：pattern的编写与&lt;xsl:for-each&gt;的select属性的值类似，其中以"/"开头表示从文档的根出发搜索；以"//"开头表遍历文档的所有结点；以".."开头表示从当前结点的父结点开始；如果欲从当前结点向下搜索则不能有以上特殊字符打头。</p><p>　　示例，与当前结点同名的元素在其父元素内的个数：</p><p>childNumber(this.selectNodes("../"+this.nodeName+"[end()]").item(0))</p><p>　　当前元素内名字为"skill"的元素的个数：</p><p>childNumber(this.selectNodes("skill[end()]").item(0))</p><p>　　二十、selectSingleNode</p><p>　　含义：与selectNodes类似，不同的只返回匹配的第一个结点、而不是结点集合。</p><p>　　语法：pNode.selectSingleNode('pattern')</p><p>　　示例，与当前结点同名的元素在其父元素内的个数：</p><p>childNumber(this.selectSingleNode("../"+this.nodeName+"[end()]"))</p><p>　　当前元素内名字为"skill"的元素的个数：</p><p>childNumber(this.selectSingleNode("skill[end()]"))</p><p>　　二十一、text</p><p>　　含义：返回结点与它的子树内的文字内容。</p><p>　　语法：pNode.text</p><p>　　示例，整个文档内的文字内容：</p><p>this.ownerDocument.text</p><p>　　当前元素及其子树的文字内容：</p><p>this.text</p><p>　　二十二、xml</p><p>　　含义：返回结点及其后代的XML表示。</p><p>　　语法：pNode.xml</p><p>　　示例，当前文档的XML内容：</p><p>this.ownerDocument.xml</p><p>　　另有几个函数不作介绍，列于其下以供参考，如感兴趣，请访问http://msdn.microsoft.com获取详细说明。</p><p>formatTime(varTime, bstrFormat,varDestLocale) <br />formatDate(varDate, bstrFormat,varDestLocale)<br />apendChild(newChild)<br />definition<br />CloneNode<br />insertBefore(newChild, refChild)<br />parsed<br />removeChild(oldChild)<br />replaceChild(newChild, oldChild)<br />specified<br />transformNode(stylesheet)<br />transformNodeToObject(stylesheet,outputObject) <br />uniqueID(pNode) </p><img src ="http://www.blogjava.net/buaacaptain/aggbug/60862.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-30 14:57 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/30/60862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle 10G 在fedora core4上的安装</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/21/59302.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Thu, 20 Jul 2006 16:31:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/21/59302.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/59302.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/21/59302.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/59302.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/59302.html</trackback:ping><description><![CDATA[安装步骤: <br />

1.当然是下载软件包:<a href="http://www.oracle.com/technology/software/products/database/oracle10g/index.html" target="_blank">http://www.oracle.com/technology ... racle10g/index.html</a><br />

选择自己需要的 .我下载的是:for linux x86.(注意,下载前需要先注册用户) <br />

2.解压 <br />

 gunzip ship.db.lix32.cpio.gz <br />

 cpio -idmv &lt; ship.db.lix32.cpio <br />

解压后在当前目录下形成目录 Disk1. <br />

3.打开帮助文件.Quick Installation Guide for Linux x86 <br />

在Disk1/目录下有个DOC目录,打开里面的README文件,其中就有此帮助文件 <br />

4.安帮助一步步设至.基本没有问题. <br />

5.很重要,因为ORACLE10g不支持FC4,所以需作必要修改. <br />

z找到文件./Disk1/install/oraparam.ini,打开,删除如下内容(记得先备份) <br />

[Certified Versions] <br />

Linux=redhat-2.1,redhat-3,SuSE-9,SuSE-8,UnitedLinux-1.0 <br /><br />

[UnitedLinux-1.0-optional] <br />

TEMP_SPACE=80 <br />

SWAP_SPACE=150 <br />

MIN_DISPLAY_COLORS=256 <br /><br /><br />

[Linux-redhat-2.1-optional] <br />

TEMP_SPACE=80 <br />

SWAP_SPACE=150 <br />

MIN_DISPLAY_COLORS=256 <br /><br />

[Linux-redhat-3.0-optional] <br />

TEMP_SPACE=80 <br />

SWAP_SPACE=150 <br />

MIN_DISPLAY_COLORS=256 <br /><br />

[Linux-SuSE-9-optional] <br />

TEMP_SPACE=80 <br />

SWAP_SPACE=150 <br />

MIN_DISPLAY_COLORS=256 <br /><br />

[Linux-SuSE-8-optional] <br />

TEMP_SPACE=80 <br />

SWAP_SPACE=150 <br />

MIN_DISPLAY_COLORS=256 <br /><br />

6.设置语言支持.由于ORACLE安装界面中文支持不好,建议运行 <br />

export LC_ALL=en_us,否则容易出现乱码. <br />

好了 ,现在运行./runInstall.安向导往下走就可以了<img src ="http://www.blogjava.net/buaacaptain/aggbug/59302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-21 00:31 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/21/59302.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>小议HashMap</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/20/59178.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Thu, 20 Jul 2006 06:14:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/20/59178.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/59178.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/20/59178.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/59178.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/59178.html</trackback:ping><description><![CDATA[
		<p align="left">大家都知道，在Java里对对象的操作是基于引用的。而当我们需要对一组对象操作的时候，就需要有接收这一组引用的容器。平时我们最常用的就是数组。在Java里可以定义一个对象数组来完成许多操作。可是，数组长度是固定的，如果我们需要更加灵活的解决方案该怎么办呢？</p>
		<p align="left">Java提供了container classes来解决这一问题。container classes包括两个部分：Collection和Map。它们的结构是这样的：</p>
		<p align="left">
				<img height="492" src="http://www.frontfree.net/articles/pages/0000000695/container.gif" width="510" />
		</p>
		<p align="left">本文重点介绍HashMap。首先介绍一下什么是Map。在数组中我们是通过数组下标来对其内容索引的，而在Map中我们通过对象来对对象进行索引，用来索引的对象叫做key，其对应的对象叫做value。在下文中会有例子具体说明。</p>
		<p align="left">再来看看HashMap和TreeMap有什么区别。HashMap通过hashcode对其内容进行快速查找，而TreeMap中所有的元素都保持着某种固定的顺序，如果你需要得到一个有序的结果你就应该使用TreeMap（HashMap中元素的排列顺序是不固定的）。</p>
		<p align="left">下面就要进入本文的主题了。先举个例子说明一下怎样使用HashMap:</p>
		<table class="code" style="BORDER-COLLAPSE: collapse" bordercolor="#111111" cellspacing="0" cellpadding="4" width="100%" bgcolor="#e0e0e0" border="0">
				<tbody>
						<tr>
								<td width="100%">
										<font color="#0000ff">import</font> java.util.*; 
<p><font color="#0000ff">public class</font> Exp1 {<br />     <font color="#0000ff">public static void</font> main(String[] args){<br />          HashMap h1=<font color="#0000ff">new</font> HashMap();<br />          Random r1=<font color="#0000ff">new</font> Random();    <br />          <font color="#0000ff">for</font>(<font color="#0000ff">int</font> i=0;i&lt;1000;i++){<br />               Integer t=new Integer(r1.nextInt(20));<br />               <font color="#0000ff">if</font>(h1.containsKey(t))<br />                    ((Ctime)h1.get(t)).count++;<br />               <font color="#0000ff">else</font><br />                    h1.put(t, new Ctime());<br />          }<br />          System.out.println(h1);<br />     }<br />}</p><p><font color="#0000ff">class</font> Ctime{<br />     <font color="#0000ff">int</font> count=1;<br />     <font color="#0000ff">public</font> String toString(){<br />          <font color="#0000ff">return</font> Integer.toString(count);<br />     }<br />}</p></td>
						</tr>
				</tbody>
		</table>
		<p align="left">在HashMap中通过get()来获取value，通过put()来插入value，ContainsKey()则用来检验对象是否已经存在。可以看出，和ArrayList的操作相比，HashMap除了通过key索引其内容之外，别的方面差异并不大。</p>
		<p align="left">前面介绍了，HashMap是基于HashCode的，在所有对象的超类Object中有一个HashCode()方法，但是它和equals方法一样，并不能适用于所有的情况，这样我们就需要重写自己的HashCode()方法。下面就举这样一个例子：</p>
		<table class="code" style="BORDER-COLLAPSE: collapse" bordercolor="#111111" cellspacing="0" cellpadding="4" width="100%" bgcolor="#e0e0e0" border="0">
				<tbody>
						<tr>
								<td width="100%">
										<font color="#0000ff">import</font> java.util.*; 
<p><font color="#0000ff">public</font> class Exp2 {<br />     <font color="#0000ff">public static void</font> main(String[] args){<br />          HashMap h2=<font color="#0000ff">new</font> HashMap();<br />          <font color="#0000ff">for</font>(<font color="#0000ff">int</font> i=0;i&lt;10;i++)<br />               h2.put(<font color="#0000ff">new</font> Element(i), <font color="#0000ff">new</font> Figureout());<br />          System.out.println("h2:");<br />          System.out.println("Get the result for Element:");<br />          Element test=<font color="#0000ff">new</font> Element(5);<br />          <font color="#0000ff">if</font>(h2.containsKey(test))<br />               System.out.println((Figureout)h2.get(test));<br />          <font color="#0000ff">else</font><br />               System.out.println("Not found");<br />     }<br />}</p><p><font color="#0000ff">class</font> Element{<br />     <font color="#0000ff">int</font> number;<br />     <font color="#0000ff">public</font> Element(<font color="#0000ff">int</font> n){<br />          number=n;<br />     } <br />}</p><p><font color="#0000ff">class</font> Figureout{<br />     Random r=<font color="#0000ff">new</font> Random();<br />     <font color="#0000ff">boolean</font> possible=r.nextDouble()&gt;0.5;<br />     <font color="#0000ff">public</font> String toString(){<br />          <font color="#0000ff">if</font>(possible)<br />               <font color="#0000ff">return</font> "OK!";<br />          <font color="#0000ff">else</font><br />               <font color="#0000ff">return</font> "Impossible!";<br />     }<br />}</p></td>
						</tr>
				</tbody>
		</table>
		<p align="left">在这个例子中，Element用来索引对象Figureout,也即Element为key，Figureout为value。在Figureout中随机生成一个浮点数，如果它比0.5大，打印“OK!”，否则打印“Impossible!”。之后查看Element(3)对应的Figureout结果如何。</p>
		<p align="left">结果却发现，无论你运行多少次，得到的结果都是“Not found”。也就是说索引Element(3)并不在HashMap中。这怎么可能呢？</p>
		<p align="left">原因得慢慢来说：Element的HashCode方法继承自Object，而Object中的HashCode方法返回的HashCode对应于当前的地址，也就是说对于不同的对象，即使它们的内容完全相同，用HashCode（）返回的值也会不同。这样实际上违背了我们的意图。因为我们在使用HashMap时，希望利用相同内容的对象索引得到相同的目标对象，这就需要HashCode()在此时能够返回相同的值。在上面的例子中，我们期望new Element(i) (i=5)与 Element test=new Element(5)是相同的，而实际上这是两个不同的对象，尽管它们的内容相同，但它们在内存中的地址不同。因此很自然的，上面的程序得不到我们设想的结果。下面对Element类更改如下：</p>
		<table class="code" style="BORDER-COLLAPSE: collapse" bordercolor="#111111" cellspacing="0" cellpadding="4" width="100%" bgcolor="#e0e0e0" border="0">
				<tbody>
						<tr>
								<td width="100%">
										<font color="#0000ff">class</font> Element{<br />     <font color="#0000ff">int</font> number;<br />     <font color="#0000ff">public</font> Element(<font color="#0000ff">int</font> n){<br />          number=n;<br />     } <br />     <font color="#0000ff">public int</font> hashCode(){<br />          return number;<br />     }<br />     <font color="#0000ff">public boolean</font> equals(Object o){<br />          <font color="#0000ff">return</font> (o instanceof Element) &amp;&amp; (number==((Element)o).number);<br />     }<br />}</td>
						</tr>
				</tbody>
		</table>
		<p align="left">在这里Element覆盖了Object中的hashCode()和equals()方法。覆盖hashCode()使其以number的值作为hashcode返回，这样对于相同内容的对象来说它们的hashcode也就相同了。而覆盖equals()是为了在HashMap判断两个key是否相等时使结果有意义（有关重写equals()的内容可以参考我的另一篇文章《重新编写Object类中的方法 》）。修改后的程序运行结果如下：</p>
		<p align="left">h2:<br />Get the result for Element:<br />Impossible!</p>
		<p align="left">请记住：如果你想有效的使用HashMap，你就必须重写在其的HashCode()。</p>
		<p align="left">还有两条重写HashCode()的原则：</p>
		<ol>
				<li>不必对每个不同的对象都产生一个唯一的hashcode，只要你的HashCode方法使get()能够得到put()放进去的内容就可以了。即“不为一原则”。 
</li>
				<li>生成hashcode的算法尽量使hashcode的值分散一些，不要很多hashcode都集中在一个范围内，这样有利于提高HashMap的性能。即“分散原则”。 </li>
		</ol>
		<p>至于第二条原则的具体原因，有兴趣者可以参考Bruce Eckel的《Thinking in Java》，在那里有对HashMap内部实现原理的介绍，这里就不赘述了。</p>
		<p>掌握了这两条原则，你就能够用好HashMap编写自己的程序了。不知道大家注意没有，java.lang.Object中提供的三个方法：clone()，equals()和hashCode()虽然很典型，但在很多情况下都不能够适用，它们只是简单的由对象的地址得出结果。这就需要我们在自己的程序中重写它们，其实java类库中也重写了千千万万个这样的方法。利用面向对象的多态性——覆盖，Java的设计者很优雅的构建了Java的结构，也更加体现了Java是一门纯OOP语言的特性。</p>
		<p>Java提供的Collection和Map的功能是十分强大的，它们能够使你的程序实现方式更为灵活，执行效率更高。希望本文能够对大家更好的使用HashMap有所帮助。 </p>
<img src ="http://www.blogjava.net/buaacaptain/aggbug/59178.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-20 14:14 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/20/59178.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下挂载硬盘分区的几种方法</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/19/58884.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Tue, 18 Jul 2006 17:19:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/19/58884.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/58884.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/19/58884.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/58884.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/58884.html</trackback:ping><description><![CDATA[
		<font size="3">1、使用Autofs自动挂载分区<br />2、修改/etc/fstab<br />3、编写shell脚本，开机自动运行mount命令</font>
		<br />
		<p>
				<font style="font-weight: bold;" size="3">方法一、使用Autofs</font>
				<br />
				<font style="font-size: 11pt;">1、Autofs的特点：Autofs与Mount/Umount的不同之处在于，它是一种看守程序（deamon）。如果它检测到用户正试图访问一个尚未挂接的文件系统，它就会自动检测该文件系
统，如果该文件系统存在，那么Autofs会自动将其挂接。另一方面，如果它检测到某个已挂接的文件系统在一段时间内没有被使用，那么Autofs会自动
将其卸载。因此一旦运行了Autofs后，用户就不在需要手动完成文件系统的挂接和卸载。<br />
2、Autofs的安装：</font>
				<font style="font-size: 11pt;">只需执行以下一条命令：rpm －ivh autofs－3.1.3－10.i386.rpm。安装完成后，以后每次启动Linux，Autofs都会自动运行。<br />
3、Autofs的配置：首先，</font>
				<font style="font-size: 11pt;">Autofs需要从/etc/auto.master这个文件中读取配置信息。该文件中
可以同时指定多个挂接点，每个挂接点单独用一行来定义,每一行可包括3个部分，分别用于指定挂接点位置，挂接时需使用的配置文件（即：所谓的map
file)及所挂接文件系统在空闲多长时间后自动被卸载。例如，auto.master文件中包括如下一行：</font>
				<font style="font-size: 11pt;">/auto /etc/auto.misc －－timeout 60。</font>
				<font style="font-size: 11pt;">其
中第一部分指定一个安装点为/auto，第二部分指定/auto的map文件为/etc/auto.misc，第三部分指定文件系统在其空闲60秒后自动
被卸载。其次，从/etc/auto.misc这个文件读取挂接时需要使用的配置信息。例如，auto.misc文件包括如下内容<br />
cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom<br />
Windows_C -fstype=auto,iocharset=cp936 :/dev/hda1<br />
Windows_D -fstype=auto,iocharset=cp936 :/dev/hda5<br />
Windows_E -fstype=auto,iocharset=cp936 :/dev/hda6<br /></font>
				<font style="font-size: 11pt;">其中第一行指定将设备/dev/cdrom挂接在/auto的cd子目录中，第二行指定
将硬盘的Windows分区挂接在/auto的Windows_*子目录中。每一行的第二个值－fstype是一个可选项，用来表明所挂接的文件系统的类型和挂接选项，在
mount命令能使用挂接选项同样适用于－fstype。
修改了配置文件后，可通过执行命令“/etc/init.d/autofs restart”，使新的配置生效。
现在输入命令“ls
/auto/cd”，Autofs会自动检测光驱中是否有光盘，如果有，它会自动将其挂接在/auto/cd中，这样ls就会列出其中的内容。如果我们在
60秒内没有再次访问/auto/cd时，Autofs会自动将其卸载掉。<br />转载自：http://family.chinaok.com/showcontent.php?articleid=1674<br /></font>
		</p>
		<p>
				<font style="font-size: 11pt;">
						<br />
				</font>
		</p>
		<p>
						
						1、fstab文件的作用<br />

文件/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件，则可以通过"mount　
/directoryname"命令来加载一个文件系统，每种文件系统都对应一个独立的行，每行中的字段都有空格或tab键分开。同时fsck、
mount、umount的等命令都利用该程序。<br /><br />

2、下面是/etc/fatab文件的一个示例行： <br />

fs_spec　fs_file　fs_type　fs_options　fs_dump　fs_pass　 <br />

/dev/hda1　　　/　　　ext2　　　　　defaults　　  　1　　　　1　 <br /><br />

fs_spec 　-　该字段定义希望加载的文件系统所在的设备或远程文件系统，对于一般的本地块设备情况来说：IDE设备一般描述为
/dev/hdaXN，X是IDE
设备通道(a,　b,　or　c)，N代表分区号；SCSI设备一描述为/dev/sdaXN。对于NFS情况，格式一般为:,例如：
`knuth.aeb.nl:/'。对于procfs，使用`proc'来定义。 <br /><br />

fs_file　-　该字段描述希望的文件系统加载的目录点，对于swap设备，该字段为none；对于加载目录名包含空格的情况，用40来表示空格。 <br /><br />

fs_type　-　定义了该设备上的文件系统，一般常见的文件类型为ext2　(Linux设备的常用文件类型)、vfat(Windows系统的fat32格式)、NTFS、iso9600等。 <br />

　 <br />

fs_options　-　指定加载该设备的文件系统是需要使用的特定参数选项，多个参数是由逗号分隔开来。对于大多数系统使用"defaults"就可以满足需要。其他常见的选项包括： <br />

选项　　　　　　　　　　　　　　含义 <br />

ro　　　　　　以只读模式加载该文件系统 <br />

sync　　　　不对该设备的写操作进行缓冲处理，这可以防止在非正常关机时情况下破坏文件系统，但是却降低了计算机速度 <br />

user　　　　允许普通用户加载该文件系统 <br />

quota　　　强制在该文件系统上进行磁盘定额限制 <br />

noauto　　不再使用mount　－a命令（例如系统启动时）加载该文件系统 <br /><br />

fs_dump　-　该选项被"dump"命令使用来检查一个文件系统应该以多快频率进行转储，若不需要转储就设置该字段为0 <br /><br />

fs_pass　-　该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序，根文件系统"/"对应该字段的值应该为1，其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0<br /><br />

3、修改/etc/fstab实现自动挂载Windows分区，并显示中文目录<br />

LABEL=/  /  ext3  defaults  1 1<br />

none  /dev/pts  devpts  gid=5,mode=620  0 0<br />

none  /proc     proc    defaults        0 0<br />

none  /dev/shm  tmpfs   defaults        0 0<br />

LABEL=/usr  /usr  ext3    defaults      1 2<br />

/dev/hda9   swap  swap    defaults      0 0<br />

#添加如下几行<br />

/dev/hda1   /mnt/win_c vfat codepage=936,iocharset=cp936 0 0 <br />

/dev/hda5   /mnt/win_d vfat   codepage=936,iocharset=cp936 0 0 <br />

/dev/hda6   /mnt/win_e vfat  codepage=936,iocharset=cp936 0 0 <br /><br />

4、对部分分区格式的支持需要编译相关的支持到内核了来实现，如NTFS。<br /></p>
		<p>
				<br />
		</p>
		<p>
				<br />
		</p>
		<p>首先,以root身份登陆，在/mnt下，你要有win_c win_d win_e这几个目录，如果没有可以通过在虚拟终端分别输入mkdir
/mnt/win_c,mkdir /mnt/win_d,mkdir /mnt/win_e来建立。接着打开虚拟终端，，输入 vi
mymount，然后按insert输入如下代码：<br />

  #!/bin/bash<br />

  case $1 in<br />

     m)<br />

      mount -o iocharset=cp936 -t vfat /dev/hda1 /mnt/win_c<br />

      mount -o iocharset=cp936 -t vfat /dev/hda5 /mnt/win_d   <br />

      mount -o iocharset=cp936 -t vfat /dev/hdc6 /mnt/win_e<br />

     ;;<br />

     u)<br />

      umount -o iocharset=cp936 -t vfat /dev/hda1 /mnt/win_c<br />

      umount -o iocharset=cp936 -t vfat /dev/hda5 /mnt/win_d  <br />

      umount -o iocharset=cp936 -t vfat /dev/hda6 /mnt/win_e<br />

      ;;<br />

     esac <br />

然后按Esc输入:wq回车就可以了.第一行#!/bin/bash指定以bash shell执行此文<br />

件.case $1 in 为取的命令行参数.若为m则开始挂载,若为u则卸载.其中-o <br />

iocharset=cp936能够显示中文名.-t vfat 为指定文件系统类型为WINDOWS下的VFAT文件系<br />

统.win_c win_d win_e为目录/mnt下的子目录.<br />

到这里，该程序已经写好了.但是它还没有执行权利.我们只要输入下面这个命令就可以了.<br />

   chmod u+x mymount <br />

到这步你只要输入./mymount m,就可以挂载windows分区了.如果在/etc/rc.d/rc.local 文件中添加这一行：<br />

   sh ./root/mymount m<br />

重启后linux会自动挂载windows分区。<br /></p>
		<p>http://bbs.chinaunix.net/archiver/?tid-431527.html<br /></p>
<img src ="http://www.blogjava.net/buaacaptain/aggbug/58884.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-19 01:19 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/19/58884.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>string和stringbuffer</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/13/58031.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Thu, 13 Jul 2006 09:47:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/13/58031.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/58031.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/13/58031.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/58031.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/58031.html</trackback:ping><description><![CDATA[String和StringBuffer之概览<br />　　非可变对象一旦创建之后就不能再被改变，可变对象则可以在创建之后被改变。String对象是非可变对象，StringBuffer对象则是可变对象。为获得更佳的性能你需要根据实际情况小心谨慎地选择到底使用这两者中的某一个。下面的话题会作详细的阐述。（注意：这个章节假设读者已经具备Java的String和StringBuffer的相关基础知识。）<br /> <br />创建字符串的较佳途径<br />你可以按照以下方式创建字符串对象：<br />1. String s1 = "hello"; <br />    String s2 = "hello"; <br />2. String s3 = new String("hello");<br />    String s4 = new String("hello");<br /> <br />上面哪种方式会带来更好的性能呢？下面的代码片断用来测量二者之间的区别。<br /><br />StringTest1.java<br />package com.performance.string;<br />/** This class shows the time taken for creation of<br /> *  String literals and String objects.<br /> */<br />public class StringTest1 {<br />public static void main(String[] args){<br />    // create String literals<br />    long startTime = System.currentTimeMillis();<br />    for(int i=0;i&lt;50000;i++){<br />    String s1 = "hello";<br />    String s2 = "hello";<br />    }<br />    long endTime = System.currentTimeMillis();<br />    System.out.println("Time taken for creation of String literals : "<br />                  + (endTime - startTime) + " milli seconds" );<br />    // create String objects using 'new' keyword       <br />    long startTime1 = System.currentTimeMillis();<br />    for(int i=0;i&lt;50000;i++){<br />    String s3 = new String("hello");<br />    String s4 = new String("hello");<br />    }<br />    long endTime1 = System.currentTimeMillis();<br />    System.out.println("Time taken for creation of String objects : "<br />                  + (endTime1 - startTime1)+" milli seconds");<br />    }<br />}<br />这段代码的输出：<br />Time taken for creation of String literals : 0 milli seconds<br />Time taken for creation of String objects : 170 milli seconds<br /> <br />JVM是怎样处理字符串的呢？<br />　　Java虚拟机会维护一个内部的滞留字符串对象的列表（唯一字符串的池）来避免在堆内存中产生重复的String对象。当JVM从class文件里加载字符串字面量并执行的时候，它会先检查一下当前的字符串是否已经存在于滞留字符串列表，如果已经存在，那就不会再创建一个新的String对象而是将引用指向已经存在的String对象，JVM会在内部为字符串字面量作这种检查，但并不会为通过new关键字创建的String对象作这种检查。当然你可以明确地使用String.intern()方法强制JVM为通过 new关键字创建的String对象作这样的检查。这样可以强制JVM检查内部列表而使用已有的String对象。<br />　　所以结论是，JVM会内在地为字符串字面量维护一些唯一的String对象，程序员不需要为字符串字面量而发愁，但是可能会被一些通过 new关键字创建的String对象而困扰，不过他们可以使用intern()方法来避免在堆内存上创建重复的String对象来改善Java的运行性能。下一小节会向大家展示更多的信息。<br /> <br />下图展示了未使用intern()方法来创建字符串的情况。<br /> <br />string_creating_without_intern() method<br />　　你可以自己使用==操作符和String.equals()方法来编码测试上面提到的区别。==操作符会返回true如果一些引用指向一个相同的对象但不会判断String对象的内容是否相同；String.equals()方法会返回true如果被操作的String对象的内容相同。对于上面的代码会有s1==s2，因为s1和s2两个引用指向同一个对象，对于上面的代码，s3.equals(s4)会返回true因为两个对象的内容都一样为”hello”。你可以从上图看出这种机制。在这里有三个独立的包含了相同的内容（”hello”）的对象，实际上我们不需要这么三个独立的对象—— 因为要运行它们的话既浪费时间又浪费内存。<br /> <br />　　那么怎样才能确保String对象不会重复呢？下一个话题会涵盖对于内建String机制的兴趣。<br /> <br />滞留字符串的优化作用<br />　　同一个字符串对象被重复地创建是不必要的，String.intern ()方法可以避免这种情况。下图说明了String.intern()方法是如何工作的，String.intern()方法检查字符串对象的存在性，如果需要的字符串对象已经存在，那么它会将引用指向已经存在的字符串对象而不是重新创建一个。下图描绘了使用了intern()方法的字符串字面量和字符串对象的创建情况。<br /> <br />string_creating_with_intern() method<br />下面的例程帮助大家了解String.intern()方法的重要性。<br />StringTest2.java<br /> <br />package com.performance.string;<br />// This class shows the use of intern() method to improve performance<br />public class StringTest2 {<br />public static void main(String[] args){<br />    // create String references like s1,s2,s3...so on..<br />    String variables[] = new String[50000];<br />    for( int i=0;i&lt;variables.length;i++){<br />        variables[i] = "s"+i;<br />    }<br />    // create String literals<br />    long startTime0 = System.currentTimeMillis();<br />    for(int i=0;i&lt;variables.length;i++){<br />        variables[i] = "hello";<br />    }<br />    long endTime0 = System.currentTimeMillis();<br />    System.out.println("Time taken for creation of String literals : "<br />                         + (endTime0 - startTime0) + " milli seconds" );<br />    // create String objects using 'new' keyword       <br />    long startTime1 = System.currentTimeMillis();<br />    for(int i=0;i&lt;variables.length;i++){<br />        variables[i] = new String("hello");<br />    }<br />    long endTime1 = System.currentTimeMillis();<br />    System.out.println("Time taken for creation of String objects with 'new' key word : "<br />                        + (endTime1 - startTime1)+" milli seconds");<br />    // intern String objects with intern() method   <br />    long startTime2 = System.currentTimeMillis();<br />    for(int i=0;i&lt;variables.length;i++){<br />        variables[i] = new String("hello");<br />        variables[i] = variables[i].intern();<br />    }<br />    long endTime2 = System.currentTimeMillis();<br />    System.out.println("Time taken for creation of String objects with intern(): "<br />                        + (endTime2 - startTime2)+" milli seconds");<br />    }<br />}<br />这是上面那段代码的输出结果：<br />Time taken for creation of String literals : 0 milli seconds<br />Time taken for creation of String objects with 'new' key word : 160 milli seconds<br />Time taken for creation of String objects with intern(): 60 milli seconds<br /> <br />连接字符串时候的优化技巧<br />　　你可以使用+操作符或者String.concat()或者StringBuffer.append()等办法来连接多个字符串，那一种办法具有最佳的性能呢？<br />　　如何作出选择取决于两种情景，第一种情景是需要连接的字符串是在编译期决定的还是在运行期决定的，第二种情景是你使用的是 StringBuffer还是String。通常程序员会认为StringBuffer.append()方法会优于+操作符或 String.concat()方法，但是在一些特定的情况下这个假想是不成立的。<br /> <br />1) 第一种情景：编译期决定相对于运行期决定<br />请看下面的StringTest3.java代码和输出结果。<br /><br />package com.performance.string;<br />/** This class shows the time taken by string concatenation at compile time and run time.*/<br />public class StringTest3 {<br />  public static void main(String[] args){<br />    //Test the String Concatination<br />    long startTime = System.currentTimeMillis();<br />    for(int i=0;i&lt;5000;i++){<br />    String result = "This is"+ "testing the"+ "difference"+ "between"+<br />            "String"+ "and"+ "StringBuffer";<br />    }<br />    long endTime = System.currentTimeMillis();<br />    System.out.println("Time taken for string concatenation using + operator : "<br />         + (endTime - startTime)+ " milli seconds");<br />    //Test the StringBuffer Concatination<br />    long startTime1 = System.currentTimeMillis();<br />    for(int i=0;i&lt;5000;i++){<br />    StringBuffer result = new StringBuffer();<br />         result.append("This is");<br />        result.append("testing the");<br />        result.append("difference");<br />        result.append("between");<br />       result.append("String");<br />       result.append("and");<br />       result.append("StringBuffer");<br />     }<br />    long endTime1 = System.currentTimeMillis();<br />    System.out.println("Time taken for String concatenation using StringBuffer : "<br />           + (endTime1 - startTime1)+ " milli seconds");<br />  }<br />}<br />这是上面的代码的输出结果：<br />Time taken for String concatenation using + operator : 0 milli seconds<br />Time taken for String concatenation using StringBuffer : 50 milli seconds<br />很有趣地，+操作符居然比StringBuffer.append()方法要快，为什么呢？<br /> <br />　　这里编译器的优化起了关键作用，编译器像下面举例的那样简单地在编译期连接多个字符串。它使用编译期决定取代运行期决定，在你使用new关键字来创建String对象的时候也是如此。<br /> <br />编译前：<br />String result = "This is"+"testing the"+"difference"+"between"+"String"+"and"+"StringBuffer";<br />编译后：<br />String result = "This is testing the difference between String and StringBuffer";<br /><br />这里String对象在编译期就决定了而StringBuffer对象是在运行期决定的。运行期决定需要额外的开销当字符串的值无法预先知道的时候，编译期决定作用于字符串的值可以预先知道的时候，下面是一个例子。<br /> <br />编译前：<br />public String getString(String str1,String str2) {<br />    return str1+str2;<br />}<br />编译后：<br />return new StringBuffer().append(str1).append(str2).toString();<br />运行期决定需要更多的时间来运行。<br /> <br />2) 第二种情景：使用StringBuffer取代String<br />看看下面的代码你会发现与情景一相反的结果——连接多个字符串的时候StringBuffer要比String快。<br />StringTest4.java<br /> <br />package com.performance.string;<br />/** This class shows the time taken by string concatenation<br />using + operator and StringBuffer  */<br />public class StringTest4 {<br /> public static void main(String[] args){<br />    //Test the String Concatenation using + operator<br />    long startTime = System.currentTimeMillis();<br />    String result = "hello";<br />    for(int i=0;i&lt;1500;i++){<br />        result += "hello";<br />    }<br />    long endTime = System.currentTimeMillis();<br />    System.out.println("Time taken for string concatenation using + operator : "<br />                  + (endTime - startTime)+ " milli seconds");<br />    //Test the String Concatenation using StringBuffer<br />    long startTime1 = System.currentTimeMillis();<br />    StringBuffer result1 = new StringBuffer("hello");<br />    for(int i=0;i&lt;1500;i++){<br />        result1.append("hello");<br />    }<br />    long endTime1 = System.currentTimeMillis();<br />    System.out.println("Time taken for string concatenation using StringBuffer :  "<br />                  + (endTime1 - startTime1)+ " milli seconds");<br />    }<br />}<br />这是上面的代码的输出结果：<br />Time taken for string concatenation using + operator : 280 milli seconds<br />Time taken for String concatenation using StringBuffer : 0 milli seconds<br />看得出StringBuffer.append()方法要比+操作符要快得多，为什么呢？<br /><br />　　原因是两者都是在运行期决定字符串对象，但是+操作符使用不同于StringBuffer.append()的规则通过String和StringBuffer来完成字符串连接操作。（译注：什么样的规则呢？）<br /> <br />借助StringBuffer的初始化过程的优化技巧<br />　　你可以通过StringBuffer的构造函数来设定它的初始化容量，这样可以明显地提升性能。这里提到的构造函数是StringBuffer(int length)，length参数表示当前的StringBuffer能保持的字符数量。你也可以使用ensureCapacity(int minimumcapacity)方法在StringBuffer对象创建之后设置它的容量。首先我们看看StringBuffer的缺省行为，然后再找出一条更好的提升性能的途径。<br /> <br />StringBuffer的缺省行为：<br />　　StringBuffer在内部维护一个字符数组，当你使用缺省的构造函数来创建StringBuffer对象的时候，因为没有设置初始化字符长度，StringBuffer的容量被初始化为16个字符，也就是说缺省容量就是16个字符。当StringBuffer达到最大容量的时候，它会将自身容量增加到当前的2倍再加2，也就是（2*旧值+2）。<br />　　如果你使用缺省值，初始化之后接着往里面追加字符，在你追加到第16个字符的时候它会将容量增加到34（2*16+2），当追加到34个字符的时候就会将容量增加到70（2*34+2）。无论何事只要StringBuffer到达它的最大容量它就不得不创建一个新的字符数组然后重新将旧字符和新字符都拷贝一遍——这也太昂贵了点。所以总是给StringBuffer设置一个合理的初始化容量值是错不了的，这样会带来立竿见影的性能增益。<br />　　我利用两个StringBuffer重新测试了上面的StringTest4.java代码，一个未使用初始化容量值而另一个使用了。这次我追加了50000个’hello’对象没有使用+操作符。区别是我使用StringBuffer(250000)的构造函数来初始化第二个 StringBuffer了。<br /> <br />输出结果如下：<br />Time taken for String concatenation using StringBuffer with out setting size: 280 milli seconds<br />Time taken for String concatenation using StringBuffer with setting size: 0 milli seconds<br />StringBuffer初始化过程的调整的作用由此可见一斑。所以，使用一个合适的容量值来初始化StringBuffer永远都是一个最佳的建议。<br /> <br />关键点<br />1. 无论何时只要可能的话使用字符串字面量来常见字符串而不是使用new关键字来创建字符串。<br />2. 无论何时当你要使用new关键字来创建很多内容重复的字符串的话，请使用String.intern()方法。<br />3. +操作符会为字符串连接提供最佳的性能——当字符串是在编译期决定的时候。<br />4. 如果字符串在运行期决定，使用一个合适的初期容量值初始化的StringBuffer会为字符串连接提供最佳的性能<br /><br /><a href="http://java.chinaitlab.com/JDK/364481.html">http://java.chinaitlab.com/JDK/364481.html</a><img src ="http://www.blogjava.net/buaacaptain/aggbug/58031.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-13 17:47 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/13/58031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xml的document和xml字符串间的转换</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/13/57953.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Thu, 13 Jul 2006 04:52:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/13/57953.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/57953.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/13/57953.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/57953.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/57953.html</trackback:ping><description><![CDATA[
		<table cellspacing="1" cellpadding="4" width="100%" border="0">
				<tbody>
						<tr>
								<td valign="top">
										<div class="subhead">
												<b>XML字符串和XML DOCUMENT的相互转换</b>
										</div>
								</td>
						</tr>
						<tr>
								<td class="content" valign="top">
										<table width="200" align="right" border="0">
												<tbody>
														<tr>
																<td>
																</td>
														</tr>
												</tbody>
										</table>
										<p>
												<font size="2">在做一般的XML数据交换过程中，我更乐意传递XML字符串，而不是格式化的XML Document。这就涉及到XML字符串和Xml Document的转换问题，说白了这是个很简单的问题，本文就各种XML解析器分别列举如下，以方便自己今后查阅。</font>
										</p>
										<p>
												<br />
												<strong>
														<font size="2">一、使用最原始的javax.xml.parsers，标准的jdk api</font>
												</strong>
										</p>
										<p>
												<font size="2">// 字符串转XML<br />String xmlStr = \"......\";<br />StringReader sr = new StringReader(xmlStr); <br />InputSource is = new InputSource(sr); <br />DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); <br />DocumentBuilder builder=factory.newDocumentBuilder(); <br />Document doc = builder.parse(is); </font>
										</p>
										<p>
												<font size="2">//XML转字符串<br />TransformerFactory  tf  =  TransformerFactory.newInstance();<br />Transformer t = tf.newTransformer();<br />t.setOutputProperty(\"encoding\",\"GB23121\");//解决中文问题，试过用GBK不行<br />ByteArrayOutputStream  bos  =  new  ByteArrayOutputStream();<br />t.transform(new DOMSource(doc), new StreamResult(bos));<br />String xmlStr = bos.toString();</font>
										</p>
										<p>
												<font size="2">这里的XML DOCUMENT为org.w3c.dom.Document</font>
										</p>
										<p>
												<strong>
														<font size="2">二、使用dom4j后程序变得更简单</font>
												</strong>
										</p>
										<p>
												<font size="2">// 字符串转XML<br />String xmlStr = \"......\";<br />Document document = DocumentHelper.parseText(xmlStr);</font>
										</p>
										<p>
												<font size="2">// XML转字符串 <br />Document document = ...;<br />String text = document.asXML();</font>
										</p>
										<p>
												<font size="2">这里的XML DOCUMENT为org.dom4j.Document</font>
										</p>
										<p>
												<strong>
														<font size="2">三、使用JDOM</font>
												</strong>
										</p>
										<p>
												<font size="2">JDOM的处理方式和第一种方法处理非常类似</font>
										</p>
										<p>
												<font size="2">//字符串转XML<br />String xmlStr = \".....\";<br />StringReader sr = new StringReader(xmlStr);<br />InputSource is = new InputSource(sr);<br />Document doc = (new SAXBuilder()).build(is);</font>
										</p>
										<p>
												<font size="2">//XML转字符串<br />Format format = Format.getPrettyFormat();<br />format.setEncoding(\"gb2312\");//设置xml文件的字符为gb2312，解决中文问题<br />XMLOutputter xmlout = new XMLOutputter(format);<br />ByteArrayOutputStream bo = new ByteArrayOutputStream();<br />xmlout.output(doc,bo);<br />String xmlStr = bo.toString();</font>
										</p>
										<p>
												<font size="2">这里的XML DOCUMENT为org.jdom.Document</font>
										</p>
										<p>
												<strong>
														<font size="2">四、JAVASCRIPT中的处理</font>
												</strong>
										</p>
										<p>
												<br />
												<font size="2">//字符串转XML<br />var xmlStr = \".....\";<br />var xmlDoc = new ActiveXObject(\"Microsoft.XMLDOM\");<br />xmlDoc.async=false;<br />xmlDoc.loadXML(xmlStr);<br />//可以处理这个xmlDoc了<br />var name = xmlDoc.selectSingleNode(\"/person/name\");<br />alert(name.text);</font>
										</p>
										<p>
												<font size="2">//XML转字符串<br />var xmlDoc = ......;<br />var xmlStr = xmlDoc.xml</font>
										</p>
										<p>
												<font size="2">这里的XML DOCUMENT为javascript版的XMLDOM</font>
										</p>
								</td>
						</tr>
				</tbody>
		</table>
<img src ="http://www.blogjava.net/buaacaptain/aggbug/57953.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-13 12:52 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/13/57953.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于clob字段的一些讨论</title><link>http://www.blogjava.net/buaacaptain/archive/2006/07/11/57616.html</link><dc:creator>船长</dc:creator><author>船长</author><pubDate>Tue, 11 Jul 2006 03:07:00 GMT</pubDate><guid>http://www.blogjava.net/buaacaptain/archive/2006/07/11/57616.html</guid><wfw:comment>http://www.blogjava.net/buaacaptain/comments/57616.html</wfw:comment><comments>http://www.blogjava.net/buaacaptain/archive/2006/07/11/57616.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/buaacaptain/comments/commentRss/57616.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/buaacaptain/services/trackbacks/57616.html</trackback:ping><description><![CDATA[在网上闲逛找到了解决方案：<br />     现在3.x中对blob和clob增加了org.hibernate.lob.SerializableBlob和org.hibernate.lob.SerializableClob类的封装。<br /><br />其次如果你将前面的测试程序放到weblogic的容器中通过weblogic的数据源得到连接的话，你会发现oracle.sql.BLOB blob = (oracle.sql.BLOB)person.getImage();和 oracle.sql.CLOB clob = (oracle.sql.CLOB)person.getArticle();这俩行会出错，原因就是weblogic进行了包装。<br /><br />现在将以上两个问题的综合解决方案用以下代码说明：<br /><br /><br /><br />            for (int i = 0; i &lt; 10; i++) {<br />                LargeObject large = new LargeObject();<br />                large.setId(i + "");<br />                large.setName("林意炜");<br /><br />                // 插入一个小数据数据<br />                large.setImage(Hibernate.createBlob(new byte[1]));<br />                large.setArticle(Hibernate.createClob(" "));<br /><br />                session.save(large);<br />                session.flush();<br /><br />                // 锁定该记录<br />                session.refresh(large, LockMode.UPGRADE);<br /><br />                // 插入图片数据<br />                String fileName = "E:/AAA/" + i + ".jpg";<br />                SerializableBlob sb = (SerializableBlob)large.getImage();<br />                java.sql.Blob wrapBlob = sb.getWrappedBlob();<br />                // 通过非weblogic容器中数据源获得连接的情况<br />                if(wrapBlob instanceof oracle.sql.BLOB){<br />                    oracle.sql.BLOB blob = (oracle.sql.BLOB) wrapBlob;<br />                    OutputStream out = blob.getBinaryOutputStream();<br />                    out.write(getData(fileName));<br />                    out.close();<br />                }<br />                // 使用weblogic的Oracle Thin driver类型连接池，驱动类名：oracle.jdbc.OracleDriver<br />                else if(wrapBlob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob){<br />                    OracleThinBlob blob = (OracleThinBlob)wrapBlob;<br />                    OutputStream out = blob.getBinaryOutputStream();<br />                    out.write(getData(fileName));<br />                    out.close();<br />                }<br /><br /><br />                // 插入文章数据<br />                fileName = "E:/AAA/" + i + ".java";<br />                SerializableClob cb = (SerializableClob)large.getArticle();<br />                java.sql.Clob wrapClob = cb.getWrappedClob();<br />                // 通过非weblogic容器中数据源获得连接的情况<br />                if(wrapClob instanceof oracle.sql.CLOB){<br />                    oracle.sql.CLOB clob = (oracle.sql.CLOB) wrapClob;<br />                    Writer writer = clob.getCharacterOutputStream();<br />                    String article = new String(getData(fileName));<br />                    writer.write(article);<br />                    writer.close();<br />                }<br />                // 使用weblogic的Oracle Thin driver类型连接池，驱动类名：oracle.jdbc.OracleDriver<br />                else if(wrapClob instanceof weblogic.jdbc.vendor.oracle.OracleThinClob){<br />                    OracleThinClob clob = (OracleThinClob)wrapClob;<br />                    Writer writer = clob.getCharacterOutputStream();<br />                    String article = new String(getData(fileName));<br />                    writer.write(article);<br />                    writer.close();<br />                }<br />            }<br /><br /><br />***************************************************<br /><span class="postbody">采用得是ORACLE9i数据库，Jboss或Weblogic。 <br />JDBC采用ORACLE9i自带的Class12.jar <br />－－－－－－－－－－－－－ <br />数据库结构： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />CREATE TABLE SNCPARAMETERS <br /><span style="COLOR: #000000">(</span><br />  ID     NUMBER<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">19</span><span style="COLOR: #000000">)</span>                             NOT <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">NULL</span>, <br />  SNCID  NUMBER<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">19</span><span style="COLOR: #000000">)</span>, <br />  NAME   VARCHAR2<span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">255</span><span style="COLOR: #000000">)</span>, <br />  VALUE  CLOB <br /><span style="COLOR: #000000">)</span><br /></div><br /></td></tr></tbody></table><span class="postbody"><br />－－－－－－－－－－－－－－ <br />BO采用xdoclet建立的： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br /><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> SNCParameters <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">extends</span> BaseObject <br /><span style="COLOR: #000000">{</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the id. <br />     * <br />     * @return      long <br />     * @hibernate.id <br />     *          column = "id" <br />     *          type = "long" <br />     *          generator-class = "native" <br />     *          unsaved-value = "null" <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Long</span> getId<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> id; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Id attribute of the SNCParameters object <br />     * <br />     * @param    id  The new Id value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setId<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span> id<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">id</span> = id; <br />    <span style="COLOR: #000000">}</span><br /><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the name. <br />     * <br />     * @return      String <br />     * <br />     * @hibernate.property <br />     *          column = "name" <br />     *          type = "string" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">String</span> getName<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> name; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Name attribute of the SNCParameters object <br />     * <br />     * @param    name  The new Name value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setName<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span> name<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">name</span> = name; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the sncId. <br />     * <br />     * @return      Long <br />     * <br />     * @hibernate.property <br />     *          column = "sncId" <br />     *          type = "long" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Long</span> getSncId<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> sncId; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the SncId attribute of the SNCParameters object <br />     * <br />     * @param    sncId  The new SncId value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setSncId<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span> sncId<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">sncId</span> = sncId; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     * Returns the values. <br />     * <br />     * @return      Clob <br />     * <br />     * @hibernate.property <br />     *          column = "value" <br />     *          type = "clob" <br />     *          not-null = "true" <br />     *          unique = "false" <br />     */</span><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">Clob</span> getValue<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> value; <br />    <span style="COLOR: #000000">}</span><br /><br />    <span style="COLOR: #6666ff">/** <br />     *    Sets the Values attribute of the SNCParameters object <br />     * <br />     * @param    values  The new Values value <br />     */</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setValue<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Clob</span> value<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">value</span> = value; <br />    <span style="COLOR: #000000">}</span><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Long</span> id; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Long</span> sncId; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">String</span> name; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">Clob</span> value; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">private</span><span style="COLOR: #aaaadd" ?="">String</span> valueString; <br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">String</span> getValueString<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> valueString; <br />    <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> setValueString<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">String</span>  valueString<span style="COLOR: #000000">)</span><br />    <span style="COLOR: #000000">{</span><br />        this.<span style="COLOR: #000000">valueString</span> = valueString; <br />    <span style="COLOR: #000000">}</span><br /><span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span class="postbody"><br /><br /><span style="FONT-WEIGHT: bold">注：valueString并不映射到数据库的CLOB字段，只是方便需要使用这个BO的人用GET、SET 处理这个巨长的CLOB字段</span><br />－－－－－－－－－－－－ <br />xdocLet生成的XML文件： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />&lt;?xml version="<span style="COLOR: #000000" ?="">1</span>.<span style="COLOR: #000000" ?="">0</span>"?&gt; <br /><br />&lt;!DOCTYPE hibernate-mapping <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">PUBLIC</span><br />    "-<span style="COLOR: #6666ff">//Hibernate/Hibernate Mapping DTD 2.0//EN" </span><br />    "http:<span style="COLOR: #6666ff">//hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"&gt;</span><br /><br />&lt;hibernate-mapping&gt; <br />    &lt;<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span><br />        name="com.<span style="COLOR: #000000">idncn</span>.<span style="COLOR: #000000">mc</span>.<span style="COLOR: #000000">bo</span>.<span style="COLOR: #000000">SNCParameters</span>" <br />        table="SNCParameters" <br />        dynamic-update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        dynamic-insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />    &gt; <br /><br />        &lt;id <br />            name="id" <br />            column="id" <br />            type="long" <br />            unsaved-value="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>" <br />        &gt; <br />            &lt;generator <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span>="native"&gt; <br />            &lt;/generator&gt; <br />        &lt;/id&gt; <br /><br />        &lt;property <br />            name="name" <br />            type="string" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="name" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /&gt; <br /><br />        &lt;property <br />            name="sncId" <br />            type="long" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="sncId" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /&gt; <br /><br />        &lt;property <br />            name="value" <br />            type="clob" <br />            update="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            insert="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            column="value" <br />            not-<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span>="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">true</span>" <br />            unique="<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">false</span>" <br />        /&gt; <br />    &lt;/<span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span>&gt; <br /><br />&lt;/hibernate-mapping&gt; <br /></div><br /></td></tr></tbody></table><span class="postbody"><br />－－－－－－－－－－－－－－－－－－－－ <br />insert的代码： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">List</span> batchAddSncParameters<span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">List</span> sncParametersList, <span style="COLOR: #aaaadd" ?="">Long</span> sncId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #aaaadd" ?="">List</span> ret = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">ArrayList</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>sncParametersList != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span> &amp;&amp; sncParametersList.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span> &gt; <span style="COLOR: #000000" ?="">0</span><span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">for</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> i = <span style="COLOR: #000000" ?="">0</span>; i &lt; sncParametersList.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; i++<span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    SNCParameters cp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span> sncParametersList.<span style="COLOR: #000000">get</span><span style="COLOR: #000000">(</span>i<span style="COLOR: #000000">)</span>; <br />                    long newId = -<span style="COLOR: #000000" ?="">1</span>; <br />                    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>cp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                    <span style="COLOR: #000000">{</span><br />                        SNCParameters cpNew = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> SNCParameters<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>sncId<span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                        cpNew.<span style="COLOR: #000000">setValue</span><span style="COLOR: #000000">(</span>Hibernate.<span style="COLOR: #000000">createClob</span><span style="COLOR: #000000">(</span>" "<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                        newId = <span style="COLOR: #000000">(</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">)</span> sess.<span style="COLOR: #000000">save</span><span style="COLOR: #000000">(</span>cpNew<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>.<span style="COLOR: #000000">longValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        sess.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />                        sess.<span style="COLOR: #000000">refresh</span><span style="COLOR: #000000">(</span>cpNew, LockMode.<span style="COLOR: #000000">UPGRADE</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #aaaadd" ?="">String</span> content = cp.<span style="COLOR: #000000">getValueString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />                        <span style="COLOR: #aaaadd" ?="">String</span> appserver = <span style="COLOR: #aaaadd" ?="">System</span>.<span style="COLOR: #000000">getProperty</span><span style="COLOR: #000000">(</span>"appserver", "jboss"<span style="COLOR: #000000">)</span>; <br />                        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>!appserver.<span style="COLOR: #000000">equalsIgnoreCase</span><span style="COLOR: #000000">(</span>"jboss"<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span><br />                        <span style="COLOR: #000000">{</span><br />                            <span style="COLOR: #6666ff">//weblogic</span><br />                            OracleThinClob clob = <span style="COLOR: #000000">(</span>OracleThinClob<span style="COLOR: #000000">)</span> cpNew.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>content<span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #000000">}</span><br />                        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">else</span><br />                        <span style="COLOR: #000000">{</span><br />                            <span style="COLOR: #6666ff">//jboss</span><br />                            oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span> clob = <span style="COLOR: #000000">(</span>oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span><span style="COLOR: #000000">)</span> cpNew.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>content<span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                            pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                        <span style="COLOR: #000000">}</span><br />                        ret.<span style="COLOR: #000000">add</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">(</span>newId<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #000000">}</span><br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">INSERT_OBJECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> ret; <br />    <span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span class="postbody"><br />－－－－－－－－－－－－－－－－－ <br />注：Weblogic必须使用<span style="FONT-WEIGHT: bold">weblogic.jdbc.vendor.oracle.OracleThinClob</span><br />－－－－－－－－－－－－－－－－－－－－－ <br />读取CLOB字段： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="COLOR: #aaaadd" ?="">List</span> selectSncParametersBySncId<span style="COLOR: #000000">(</span>long sncId<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #aaaadd" ?="">List</span> ret = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">ArrayList</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #aaaadd" ?="">String</span> query = "select cp from cp in <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">class</span> com.<span style="COLOR: #000000">idncn</span>.<span style="COLOR: #000000">mc</span>.<span style="COLOR: #000000">bo</span>.<span style="COLOR: #000000">SNCParameters</span> where cp.<span style="COLOR: #000000">sncId</span> = ?"; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"SQL=" + query<span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #aaaadd" ?="">List</span> iter = sess.<span style="COLOR: #000000">find</span><span style="COLOR: #000000">(</span>query, <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span><span style="COLOR: #aaaadd" ?="">Long</span><span style="COLOR: #000000">(</span>sncId<span style="COLOR: #000000">)</span>, Hibernate.<span style="COLOR: #000000">LONG</span><span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">for</span><span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span> i = <span style="COLOR: #000000" ?="">0</span>; i &lt; iter.<span style="COLOR: #000000">size</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; i++<span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                SNCParameters newCp = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> SNCParameters<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                SNCParameters cp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span><span style="COLOR: #000000">(</span>iter.<span style="COLOR: #000000">get</span><span style="COLOR: #000000">(</span>i<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"after fetch:" + cp<span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setId</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getSncId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                newCp.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>cp.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                java.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">Clob</span> clob = cp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>clob != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"b===" + clob.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #aaaadd" ?="">String</span> b = clob.<span style="COLOR: #000000">getSubString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000" ?="">1</span>, <span style="COLOR: #000000">(</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">int</span><span style="COLOR: #000000">)</span> clob.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />                    <span style="COLOR: #6666ff">//logger.debug("b==="+b);</span><br />                    newCp.<span style="COLOR: #000000">setValueString</span><span style="COLOR: #000000">(</span>b<span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />                ret.<span style="COLOR: #000000">add</span><span style="COLOR: #000000">(</span>newCp<span style="COLOR: #000000">)</span>; <br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">SELECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">return</span> ret; <br />    <span style="COLOR: #000000">}</span><br /></div><br /></td></tr></tbody></table><span class="postbody"><br />－－－－－－－－－－－－－－－ <br />更新这个字段的代码： <br /></span><table cellspacing="1" cellpadding="3" width="90%" align="center" border="0"><tbody><tr><td><span class="genmed"><b>java代码: </b></span></td></tr><tr><td class="code"><div style="FONT-FAMILY: 'Courier New', Courier, monospace"><br /><br />    <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">public</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">void</span> updateSncParameters<span style="COLOR: #000000">(</span>SNCParameters newParam<span style="COLOR: #000000">)</span><span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">throws</span> DbAccessException <br />    <span style="COLOR: #000000">{</span><br />        logger.<span style="COLOR: #000000">enterMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">try</span><br />        <span style="COLOR: #000000">{</span><br />            sess = getSession<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">Long</span> id = newParam.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            SNCParameters pp = <span style="COLOR: #000000">(</span>SNCParameters<span style="COLOR: #000000">)</span> sess.<span style="COLOR: #000000">load</span><span style="COLOR: #000000">(</span>SNCParameters.<span style="COLOR: #000000">class</span>, id, net.<span style="COLOR: #000000">sf</span>.<span style="COLOR: #000000">hibernate</span>.<span style="COLOR: #000000">LockMode</span>.<span style="COLOR: #000000">UPGRADE</span><span style="COLOR: #000000">)</span>; <br /><br />            pp.<span style="COLOR: #000000">setSncId</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getSncId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />            pp.<span style="COLOR: #000000">setName</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getName</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br />            pp.<span style="COLOR: #000000">setId</span><span style="COLOR: #000000">(</span>newParam.<span style="COLOR: #000000">getId</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">String</span> newValue = newParam.<span style="COLOR: #000000">getValueString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"Update Length =" + newValue.<span style="COLOR: #000000">length</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span>; <br /><br />            <span style="COLOR: #aaaadd" ?="">String</span> appserver = <span style="COLOR: #aaaadd" ?="">System</span>.<span style="COLOR: #000000">getProperty</span><span style="COLOR: #000000">(</span>"appserver", "jboss"<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">debug</span><span style="COLOR: #000000">(</span>"appserver: " + appserver<span style="COLOR: #000000">)</span>; <br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>!appserver.<span style="COLOR: #000000">equalsIgnoreCase</span><span style="COLOR: #000000">(</span>"jboss"<span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="COLOR: #6666ff">//weblogic</span><br />                OracleThinClob clob = <span style="COLOR: #000000">(</span>OracleThinClob<span style="COLOR: #000000">)</span> pp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>pp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>newValue<span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />            <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">else</span><br />            <span style="COLOR: #000000">{</span><br />                <span style="COLOR: #6666ff">//jboss</span><br />                oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span> clob = <span style="COLOR: #000000">(</span>oracle.<span style="COLOR: #000000">sql</span>.<span style="COLOR: #000000">CLOB</span><span style="COLOR: #000000">)</span> pp.<span style="COLOR: #000000">getValue</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">if</span><span style="COLOR: #000000">(</span>pp != <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">null</span><span style="COLOR: #000000">)</span><br />                <span style="COLOR: #000000">{</span><br />                    java.<span style="COLOR: #000000">io</span>.<span style="COLOR: #000000">Writer</span> pw = clob.<span style="COLOR: #000000">getCharacterOutputStream</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">write</span><span style="COLOR: #000000">(</span>newValue<span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">flush</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                    pw.<span style="COLOR: #000000">close</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />                <span style="COLOR: #000000">}</span><br />            <span style="COLOR: #000000">}</span><br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">catch</span><span style="COLOR: #000000">(</span><span style="COLOR: #aaaadd" ?="">Exception</span> e<span style="COLOR: #000000">)</span><br />        <span style="COLOR: #000000">{</span><br />            logger.<span style="COLOR: #000000">error</span><span style="COLOR: #000000">(</span>e<span style="COLOR: #000000">)</span>; <br />            ErrorReason errorReason = <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> ErrorReason<span style="COLOR: #000000">(</span>ErrorReason.<span style="COLOR: #000000">UPDATE_OBJECT_FAILED_REASON</span><span style="COLOR: #000000">)</span>; <br />            throw <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">new</span> DbAccessException<span style="COLOR: #000000">(</span>DbAccessException.<span style="COLOR: #000000">DBA_OPERATE_EXCEPTION</span>, errorReason<span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />        <span style="FONT-WEIGHT: bold; COLOR: #990066" ?="">finally</span><br />        <span style="COLOR: #000000">{</span><br />            closeSession<span style="COLOR: #000000">(</span>sess<span style="COLOR: #000000">)</span>; <br />            logger.<span style="COLOR: #000000">exitMethod</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span>; <br />        <span style="COLOR: #000000">}</span><br />    <span style="COLOR: #000000">}</span><br /></div></td></tr></tbody></table><br /><br /><img src ="http://www.blogjava.net/buaacaptain/aggbug/57616.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/buaacaptain/" target="_blank">船长</a> 2006-07-11 11:07 <a href="http://www.blogjava.net/buaacaptain/archive/2006/07/11/57616.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>