﻿<?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-JOracle</title><link>http://www.blogjava.net/colanlei/</link><description>人都是逼出来的(=o=)</description><language>zh-cn</language><lastBuildDate>Sun, 05 Apr 2026 12:17:11 GMT</lastBuildDate><pubDate>Sun, 05 Apr 2026 12:17:11 GMT</pubDate><ttl>60</ttl><item><title>web.config connectionStrings 数据库连接字符串的解释</title><link>http://www.blogjava.net/colanlei/archive/2010/05/19/321351.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Wed, 19 May 2010 03:28:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2010/05/19/321351.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/321351.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2010/05/19/321351.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/321351.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/321351.html</trackback:ping><description><![CDATA[
		<p>先来看一下默认的连接SQL Server数据库配置<br />&lt;connectionStrings&gt;<br />   &lt;add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /&gt;<br />&lt;/connectionStrings&gt;</p>
		<p>SqlConnectionStringBuilder实例化时需要使用connectionString。如：SqlConnectionStringBuild builder = new SqlConnectionStringBuild(connectionString);</p>
		<p>
				<br />一、Data Source<br />SqlConnectionStringBuilder的DataSource属性，对应connectionString中的Data Source，“Data Source”可以由下列字符串代替：“Server”，“Address”，“Addr”和“Network Address”。<br />Data Source=.\SQLExpress也可以写成这样Data Source=(local)\SQLExpress。</p>
		<p>二、Integrated Security<br />SqlConnectionStringBuilder 的 IntegratedSecurity 属性，对应 connectionString 中的I ntegrated Security，“Integrated Security”可以写成“trusted_connection”。<br />为 True 时，使用当前的 Windows 帐户凭据进行身份验证，为 False 时，需要在连接中指定用户 ID 和密码。可识别的值为 True、False、Yes、No 以及与 True 等效的 SSPI。<br />如果没有些则必须写上 uid=sa;pwd=123 之类的设置“uid”也可使用“User ID”，“pwd”也可换为“PassWord”。</p>
		<p>SSPI：Microsoft安全支持提供器接口（SSPI）是定义得较全面的公用API，用来获得验证、信息完整性、信息隐私等集成安全服务，以及用于所有分布式应用程序协议的安全方面的服务。<br />应用程序协议设计者能够利用该接口获得不同的安全性服务而不必修改协议本身。</p>
		<p>三、AttachDBFilename<br />SqlConnectionStringBuilder 的 AttachDBFilename 属性，对应 connectionString 中的 AttachDBFilename，“AttachDBFilename”可以写成“extended properties”，“initial file name”。<br />AttachDbFileName 属性指定连接打开的时候动态附加到服务器上的数据库文件的位置。<br />这个属性可以接受数据库的完整路径和相对路径（例如使用|DataDirectory|语法），在运行时这个路径会被应用程序的 App_Data 目录所代替。</p>
		<p>四、User Instance<br />SqlConnectionStringBuilder 的 UserInstance 属性，对应 connectionString 中的 User Instance ,该值指示是否将连接从默认的 SQL Server 实例重定向到在调用方帐户之下运行并且在运行时启动的实例。<br />UserInstance=true 时，SQLServerExpress 为了把数据库附加到新的实例，建立一个新的进程，在打开连接的用户身份下运行。<br />在 ASP.NET 应用程序中，这个用户是本地的 ASPNET 帐号或默认的 NetworkService，这依赖于操作系统。<br />为了安全地附加非系统管理员帐号（例如ASP.NET帐号）提供的数据库文件，建立一个独立的 SQLServer 用户实例是必要的。</p>
		<p>五、Initial Catalog 等同于 Database。</p>
		<p>六、providerName 指定值“System.Data.OracleClient”，该值指定 ASP.NET 在使用此连接字符串进行连接时应使用 ADO.NET System.Data.OracleClient 提供程序。</p>
		<p>
				<br />PS：<br />DataDirectory是什么?</p>
		<p>asp.net 2.0有一个特殊目录app_data,通常Sql Server 2005 express数据文件就放在这个目录，相应的数据库连接串就是：<br />connectionString="…… data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|data.mdf;User Instance=true"<br />这里有一个DataDirectory的宏，它表示什么意义呢？</p>
		<p>DataDirectory是表示数据库路径的替换字符串。由于无需对完整路径进行硬编码，DataDirectory 简化了项目的共享和应用程序的部署。例如，无需使用以下连接字符串： <br />"Data Source= c:\program files\MyApp\app_data\Mydb.mdf" <br />通过使用|DataDirectory|（包含在如下所示的竖线中），即可具有以下连接字符串： <br />"Data Source = |DataDirectory|\Mydb.mdf" 。</p>
		<p>不仅仅是Sql server 2005 express中使用，也可以在其它的文件数据库中使用，例如Sqllite数据库文件的连接字符串：</p>
		<p>&lt;add name="DefaultDB" <br />connectionString="DriverClass=NHibernate.Driver.SQLite20Driver;Dialect=NHibernate.Dialect.SQLiteDialect;Data Source=|DataDirectory|\data.db3" /&gt;</p>
		<p>
				<br />---------------------------------------    附加一些连接语句例子    ---------------------------------------</p>
		<p>&lt;--普通例子1--&gt;<br />&lt;configuration&gt;<br />&lt;connectionStrings&gt;<br />    &lt;add name="Sales" providerName="System.Data.SqlClient" connectionString="server=myserver;database=Products;uid=salesUser;pwd=sellMoreProducts" /&gt;</p>
		<p>    &lt;add name="NorthWind" providerName="System.Data.SqlClient" connectionString="server=.;database=NorthWind;Integrated Security=SSPI" /&gt;</p>
		<p>&lt;/connectionStrings&gt;<br />&lt;/configuration&gt;</p>
		<p>&lt;--普通例子2--&gt;<br />&lt;configuration&gt;<br />&lt;connectionStrings&gt;<br />    &lt;add name="NorthWind" connectionString="Provider=SQLOLEDB;Integrated Security=SSPI;Initial Catalog=da;Data Source=bar" /&gt;<br />&lt;/configuration&gt;</p>
		<p>----------------------------------------------------------------------------------------------------------</p>
		<p>&lt;connectionStrings&gt;<br />   &lt;add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Initial Catalog=NorthWind;Integrated Security=SSPI" providerName="System.Data.SqlClient" /&gt;<br />&lt;/connectionStrings&gt;<br />&lt;--也可写为--&gt;<br />&lt;connectionStrings&gt;<br />   &lt;add name="LocalSqlServer" connectionString="Server=.\SQLExpress;Database=NorthWind;Integrated Security=Yes" providerName="System.Data.SqlClient" /&gt;<br />&lt;/connectionStrings&gt;</p>
		<p>----------------------------------------------------------------------------------------------------------</p>
		<p>&lt;configuration&gt;<br />&lt;connectionStrings&gt;<br />    &lt;add name="DB2005_2" <br />    providerName="System.Data.SqlClient" <br />    connectionString="Data Source=.;Initial Catalog=Northwind;User ID=dbtester;Password=zhi;Trusted_Connection=False;Connect Timeout=30;Min Pool Size=16;Max Pool Size=100"/&gt;</p>
		<p>    &lt;add name="DB2005_1" <br />    providerName="System.Data.SqlClient" <br />    connectionString="Server=.;Database=Northwind;User ID=dbtester;Password=zhi;Trusted_Connection=False;Connect Timeout=30;Min Pool Size=16;Max Pool Size=100"/&gt;</p>
		<p>    &lt;add name="Northword2000" <br />    providerName="System.Data.SqlClient" <br />    connectionString="Initial Catalog=Northwind;User ID=dbtester;PassWord=zhi;Persist Security Info=false;Data Source=(local);Connect Timeout=30;Min Pool Size=16;Max Pool Size=100;"/&gt;</p>
		<p>    &lt;add name="SQLExp"<br />       providerName="System.Data.SqlClient"<br />       connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\northwnd1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"/&gt;<br />    <br />    &lt;add name="Oracle" <br />      connectionString="Data Source=TEST;User ID=sa;Password=sa;" <br />      providerName="System.Data.OracleClient" /&gt;</p>
		<p>    &lt;add name="oleconn" <br />       providerName="System.Data.OleDb" <br />       connectionString="Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|northwind.mdb"/&gt;</p>
		<p>    &lt;add name="MySql"<br />    providerName="MySql.Data.MySqlClient" <br />    connectionString="Server=172.29.131.27;Port=3311;DataBase=comctl;Persist Security Info=False;User ID=root;Password=123456;Allow Zero Datetime=true;" /&gt;<br />&lt;/connectionStrings&gt;<br />    &lt;system.data&gt;<br />        &lt;DbProviderFactories&gt;<br />            &lt;add name="MySQL Data Provider"<br />                 invariant="MySql.Data.MySqlClient"<br />                 description=".Net Framework Data Provider for MySQL"<br />                 type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.2.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/&gt;<br />        &lt;/DbProviderFactories&gt;<br />    &lt;/system.data&gt;<br />&lt;/configuration&gt;</p>
		<p>======================================      可以保存为（以下转自他处）.cs      ======================================</p>
		<p>using System.Data.SqlClient;<br />using System.Configuration;<br />public class Class1<br />{<br />    public Class1()<br />    {<br />        //Persist Security Info如果数据库连接成功后不再需要连接的密码,建议False<br />        //string sql2000 = "Initial Catalog=Northwind;User ID=dbtester;PassWord=zhi;Persist Security Info=false;Data Source=(local);Connect Timeout=30;Min Pool Size=16;Max Pool Size=100;";<br />        //string sql2000 = "Initial Catalog=Northwind;User ID=sa;PassWord=5;Persist Security Info=false;Data Source=.";<br />        //string sql2000 = "Initial Catalog=Northwind;User ID=sa;PassWord=5;Persist Security Info=false;Data Source=newtime";<br />        string source = "server=(local);integrated security=SSPI;database=Northwind";<br />        string expressSource = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\northwnd.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";<br />        //Integrated Security采用windows的集成身份验证,integraged   Security=SSPI;<br />        //Integrated Security=SSPI 这个表示以当前WINDOWS系统用户身去登录SQL SERVER服务器，如果SQL SERVER服务器不支持这种方式登录时，就会出错<br />        //表示你的连接安全验证方式,可用trusted_connection=yes取代<br />        //Integrated Security 为 True。用户实例仅与集成安全性一起使用，带有用户名和密码的 SQL Server 用户不起作用。<br />        //string source3 = @"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog= pubs;UserID=sa;Password=asdasd;";<br />        //(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))<br />        //Standard Security: <br />        string source4 = "Data Source=Aron1;Initial Catalog= pubs;UserId=sa;Password=asdasd;";<br />        string source5 = "Server=Aron1;Database=pubs;UserID=sa;Password=asdasd;Trusted_Connection=False";<br />        //Trusted_Connection 'false' 当为 false 时，将在连接中指定用户 ID 和密码。当为 true 时，将使用当前的 Windows 帐户凭据进行身份验证。 <br />        //可识别的值为 true、false、yes、no 以及与 true 等效的 sspi（强烈推荐）。所以一定要设置Trusted_Connection= false,以防被别人"登录"、"注入语句"等 <br />        string source6 = "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;";<br />        string source7 = "Server=Aron1;Database=pubs;Trusted_Connection=True;";<br />        //(use serverName\instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)<br />        //Integrated   Security或Trusted_Connection   'false'   当为   false   时，<br />        //将在连接中指定用户   ID   和密码。当为   true   时，将使用当前的   Windows   帐户凭据进行身份验证<br />        //VS2003：string connStr=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"];2003中用的<br />        //VS2005：string connStr=System.Configuration.ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ToString();2005－8中用<br />        System.Configuration.ConnectionStringSettings i = System.Configuration.ConfigurationManager.ConnectionStrings["Northword2000"];<br />    }<br />}<br /> </p>
<img src ="http://www.blogjava.net/colanlei/aggbug/321351.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2010-05-19 11:28 <a href="http://www.blogjava.net/colanlei/archive/2010/05/19/321351.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux文件夹权限（转）</title><link>http://www.blogjava.net/colanlei/archive/2009/07/29/288880.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Wed, 29 Jul 2009 06:37:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2009/07/29/288880.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/288880.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2009/07/29/288880.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/288880.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/288880.html</trackback:ping><description><![CDATA[ 先来了解一下文件属性，<br />在shell环境里输入：ls -l 可以查看当前目录文件。如：<br />drwxr-xr-x 2 nsf users 1024 12-10 17:37 下载文件备份<br />分别对应的是：<br />文件属性 连接数 文件拥有者 所属群组 文件大小 文件修改时间 文件名<br />这里r是可读，w可写,x 可执行，其中文件属性分为四段，---- --- --- 10个位置<br />例如：<br />　　d 　 rwx 　 r-x　 r-x <br />第一个字符指定了文件类型。在通常意义上，一个目录也是一个文件。如果第一个字符是横线，表示是一个非目录的文件。如果是d，表示是一个目录。<br />第二段是文件拥有者的属性，<br />第三段是文件所属群组的属性，<br />第四段是对于其它用户的属性，<br />如上面文件夹“下载文件备份” 的访问权限，表示文件夹“下载文件备份” 是一个目录文件；文件夹“下载文件备份” 的属主有读写可执行权限；与文件夹“下载文件备份” 属主同组的用户只有读和可执行权限；其他用户也有读和可执行权限。<br />确定了一个文件的访问权限后，用户可以利用Linux系统提供的chmod命令来重新设定不同的访问权限。也可以利用chown命令来更改某个文件或目录的所有者。利用chgrp命令来更改某个文件或目录的用户组。<br /><font color="#ff0000">chmod 命令</font><br />　　功能：chmod命令是非常重要的，用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.<br />　　语法：该命令有两种用法。一种是包含字母和操作符表达式的文字设定法；另一种是包含数字的数字设定法。<br />　　1. 文字设定法<br />　　chmod [who] [+ | - | =] [mode] 文件名?<br />　　参数：<br />　　操作对象who可是下述字母中的任一个或者它们的组合：<br />　　u 表示“用户（user）”，即文件或目录的所有者。<br />　　g 表示“同组（group）用户”，即与文件属主有相同组ID的所有用户。<br />　　o 表示“其他（others）用户”。<br />　　a 表示“所有（all）用户”。它是系统默认值。<br />　　操作符号可以是：<br />　　+ 添加某个权限。<br />　　- 取消某个权限。<br />　　= 赋予给定权限并取消其他所有权限（如果有的话）。<br /><br />　　设置mode所表示的权限可用下述字母的任意组合：<br />　　r 可读。<br />　　w 可写。<br />　　x 可执行。<br />　　X 只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x 属性。<br />　　s 在文件执行时把进程的属主或组ID置为该文件的文件属主。方式“u＋s”设置文件的用         户ID位，“g＋s”设置组ID位。<br />　　t 保存程序的文本到交换设备上。<br />　　u 与文件属主拥有一样的权限。<br />　　g 与和文件属主同组的用户拥有一样的权限。<br />　　o 与其他用户拥有一样的权限。<br />　　文件名：以空格分开的要改变权限的文件列表，支持通配符。<br />　　在一个命令行中可给出多个权限方式，其间用逗号隔开。例如：chmod g+r，o+r example<br />　　使同组和其他用户对文件example 有读权限。<br /><font color="#ff0000">chgrp命令</font><br />　　功能：改变文件或目录所属的组。<br />　　语法：chgrp [选项] group filename?<br />　　该命令改变指定指定文件所属的用户组。其中group可以是用户组ID，也可以是/etc/group文件中用户组的组名。文件名是以空格分开的要改变属组的文件列表，支持通配符。如果用户不是该文件的属主或超级用户，则不能改变该文件的组。<br />　　参数：<br />　　- R 递归式地改变指定目录及其下的所有子目录和文件的属组。<br />　　例1：$ chgrp - R book /opt/local /book<br />　　改变/opt/local /book/及其子目录下的所有文件的属组为book。<br /><font color="#ff0000">chown 命令</font><br />　　功能：更改某个文件或目录的属主和属组。这个命令也很常用。例如root用户把自己的一个文件拷贝给用户xu，为了让用户xu能够存取这个文件，root用户应该把这个文件的属主设为xu，否则，用户xu无法存取这个文件。<br />　　语法：chown [选项] 用户或组 文件<br />　　说明：chown将指定文件的拥有者改为指定的用户或组。用户可以是用户名或用户ID。组可以是组名或组ID。文件是以空格分开的要改变权限的文件列表，支持通配符。<br />　　参数：<br />　　- R 递归式地改变指定目录及其下的所有子目录和文件的拥有者。<br />　　- v 显示chown命令所做的工作。<br />　　例1：把文件shiyan.c的所有者改为wang。<br />　　$ chown wang shiyan.c<br />　　例2：把目录/his及其下的所有文件和子目录的属主改成wang，属组改成users。<br />　　$ chown - R wang.users /his<img src ="http://www.blogjava.net/colanlei/aggbug/288880.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2009-07-29 14:37 <a href="http://www.blogjava.net/colanlei/archive/2009/07/29/288880.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle整库导出</title><link>http://www.blogjava.net/colanlei/articles/288218.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Fri, 24 Jul 2009 07:35:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/articles/288218.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/288218.html</wfw:comment><comments>http://www.blogjava.net/colanlei/articles/288218.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/288218.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/288218.html</trackback:ping><description><![CDATA[
		<p>今天create db instance，sqlplus 登录后遇到PLS-00201这个错：</p>
		<p>SQL&gt; set serveroutput on<br />ERROR:<br />ORA-06550: line 1, column 7:<br />PLS-00201: identifier 'DBMS_OUTPUT.ENABLE' must be declared<br />ORA-06550: line 1, column 7:<br />PL/SQL: Statement ignored<br /><br /><br />SQL&gt; exec dbms_output.enable(10000);<br />BEGIN dbms_output.enable(10000); END;<br /><br />      *<br />ERROR at line 1:<br />ORA-06550: line 1, column 7:<br />PLS-00201: identifier 'DBMS_OUTPUT.ENABLE' must be declared<br />ORA-06550: line 1, column 7:<br />PL/SQL: Statement ignored<br /></p>
		<p>解决办法：</p>
		<p>1. use sysdba to execute two <a href="javascript:;" onclick="javascript:tagshow(event, 'sql');" target="_self"><u><strong>sql</strong></u></a>(/$Oracle_home/rdbms/admin).</p>
		<p>logging as sysdba<br />try to run standard.sql,catalog.sql</p>
		<p>2. use sys and system to execute these sql scrīpt</p>as SYS (or connect internal)<br />$Oracle_home/rdbms/admin/catalog.sql<br />$Oracle_home/rdbms/admin/catsnmp.sql<br />$Oracle_home/rdbms/admin/catexp7.sql<br />$Oracle_home/rdbms/admin/catproc.sql<br />$Oracle_home/rdbms/admin/caths.sql<br />as SYSTEM (not SYS)<br />$Oracle_home/rdbms/admin/catdbsyn.sql<br /><br /><br /><b>unix 重启oracle</b><br /><br />su -oracle<br />
sqlplus / as sysdba<br />
shutdown immediate;<br />
startup<br /><img src ="http://www.blogjava.net/colanlei/aggbug/288218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2009-07-24 15:35 <a href="http://www.blogjava.net/colanlei/articles/288218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle  导出建表sql和键索引sql</title><link>http://www.blogjava.net/colanlei/archive/2008/11/21/241813.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Fri, 21 Nov 2008 02:57:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2008/11/21/241813.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/241813.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2008/11/21/241813.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/241813.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/241813.html</trackback:ping><description><![CDATA[
		<font class="f14" id="zoom">
				<font color="#000000">
						<span style="display: none;">2TrLinux联盟</span>用sqlplus链接数据库，运行以下命令<br /><span style="display: none;">2TrLinux联盟</span><br />set pagesize 0<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />set long 90000<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />set feedback off<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />set echo off <span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />spool d:/get_schema.sql <span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />SELECT DBMS_METADATA.GET_DDL(TABLE,u.table_name)<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />FROM USER_TABLES u;<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />SELECT DBMS_METADATA.GET_DDL(INDEX,u.index_name)<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />FROM USER_INDEXES u;<span style="display: none;">2TrLinux联盟</span><br /><span style="display: none;">2TrLinux联盟</span><br />spool off; </font>
		</font>
<img src ="http://www.blogjava.net/colanlei/aggbug/241813.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-11-21 10:57 <a href="http://www.blogjava.net/colanlei/archive/2008/11/21/241813.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ARRAYLIST对象的contains方法</title><link>http://www.blogjava.net/colanlei/archive/2008/10/27/236876.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Mon, 27 Oct 2008 06:58:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2008/10/27/236876.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/236876.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2008/10/27/236876.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/236876.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/236876.html</trackback:ping><description><![CDATA[ArrayList中存放的对象，他的contains方法 是调用对象的equals方法。<br />比较的是对象的地址是否相等。<br />我们可以重写对象里面的equals方法：<br /> //重写equals方法<br />    public   boolean   equals(Object   test)   {     //参数类型一定要是Object  <br />        if   (Integer.parseInt(this.id) ==Integer.parseInt(((ChatRoom)test).id))   {  <br />            return   true;  <br />        }  <br />        else   {  <br />            return   false;  <br />        }  <br />    }<br />变成之比较对象里面的id值是否相等。<img src ="http://www.blogjava.net/colanlei/aggbug/236876.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-10-27 14:58 <a href="http://www.blogjava.net/colanlei/archive/2008/10/27/236876.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>树状菜单 查询SQL</title><link>http://www.blogjava.net/colanlei/articles/234457.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Wed, 15 Oct 2008 07:36:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/articles/234457.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/234457.html</wfw:comment><comments>http://www.blogjava.net/colanlei/articles/234457.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/234457.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/234457.html</trackback:ping><description><![CDATA[
		<p>  有一表a     字段             a.dir   ,...  <br />  数据如下                      1                <br />                                1/01  <br />                                1/01/1  <br />                                1/02  <br />                                2  <br />                                。。。  <br />  表b           字段           b.dir,           b.class  <br />  数据如下                      1/01           b  <br />                                1/01           bb  <br />                                1/01/1       c  <br />                                1/01/1       cc  <br />                                1/01/1       cd  <br />                                1/02           e  <br />                                2                 f  <br />                                。。。  <br />   <br />求出对应a表每行对应b表的数据和,如下  <br />   <br />                dir               count  <br />                                1                   6  <br />                                1/01             5  <br />                                1/01/1         3  <br />                                1/02             1  <br />                                2                   1  <br />   </p>
		<p>
				<br />select   a.dir,[count]=count(b.class)  <br />  from   表a     a   join   表b   b   on   b.dir   like   a.dir+'%'  <br />  group   by   a.dir<br /></p>
<img src ="http://www.blogjava.net/colanlei/aggbug/234457.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-10-15 15:36 <a href="http://www.blogjava.net/colanlei/articles/234457.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>group by </title><link>http://www.blogjava.net/colanlei/archive/2008/08/25/224092.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Mon, 25 Aug 2008 03:10:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2008/08/25/224092.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/224092.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2008/08/25/224092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/224092.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/224092.html</trackback:ping><description><![CDATA[GROUP BY 是分组查询, 一般是和聚合函数配合使用.<br />group by 有一个原则,就是 select 后面的所有列中,没有使用聚合函数的列,必须出现在 group by 后面<br /><img src ="http://www.blogjava.net/colanlei/aggbug/224092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-08-25 11:10 <a href="http://www.blogjava.net/colanlei/archive/2008/08/25/224092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于StrutsTestCase的单元测试(Action测试方法)</title><link>http://www.blogjava.net/colanlei/articles/215710.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Fri, 18 Jul 2008 03:22:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/articles/215710.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/215710.html</wfw:comment><comments>http://www.blogjava.net/colanlei/articles/215710.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/215710.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/215710.html</trackback:ping><description><![CDATA[采用Struts中的Mock方式模拟action和actionForm进行测试
<br />基础类：STCRequestProcessor
<br />作用：Ioc 将模拟的Action,ActionForm注入到struts-config.xml中的相应的action位置
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test.sample.service.util;  <br />   </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.IOException;  <br />   </span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.HashMap;  <br />   </span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletRequest;  <br />   </span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpServletResponse;  <br />   </span><span style="color: rgb(0, 0, 0);">6</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.servlet.http.HttpSession;  <br />   </span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">.   <br />   </span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.Action;  <br />   </span><span style="color: rgb(0, 0, 0);">9</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionForm;  <br />  </span><span style="color: rgb(0, 0, 0);">10</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.ActionMapping;  <br />  </span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.action.RequestProcessor;  <br />  </span><span style="color: rgb(0, 0, 0);">12</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.struts.util.RequestUtils;  <br />  </span><span style="color: rgb(0, 0, 0);">13</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">14</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*//**</span><span style="color: rgb(0, 128, 0);"> <br />  15.  * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> administrator <br />  16.  * <br />  17.  * To change this generated comment edit the template variable "typecomment": <br />  18.  * Window&gt;Preferences&gt;Java&gt;Templates. <br />  19.  * To enable and disable the creation of type comments go to <br />  20.  * Window&gt;Preferences&gt;Java&gt;Code Generation. <br />  21.  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> STCRequestProcessor </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> RequestProcessor {  <br />  </span><span style="color: rgb(0, 0, 0);">23</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> HashMap mockActionFormMap </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap();  <br />  </span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> HashMap mockActionMap </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap();  <br />  </span><span style="color: rgb(0, 0, 0);">26</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">27</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addMockAction(String actionStr, String className)   <br />  </span><span style="color: rgb(0, 0, 0);">28</span><span style="color: rgb(0, 0, 0);">.     {  <br />  </span><span style="color: rgb(0, 0, 0);">29</span><span style="color: rgb(0, 0, 0);">.         mockActionMap.put(actionStr, className);  <br />  </span><span style="color: rgb(0, 0, 0);">30</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">31</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> addMockActionForm(String actionFormStr,String className)  <br />  </span><span style="color: rgb(0, 0, 0);">32</span><span style="color: rgb(0, 0, 0);">.     {      <br />  </span><span style="color: rgb(0, 0, 0);">33</span><span style="color: rgb(0, 0, 0);">.         mockActionFormMap.put(actionFormStr, className);  <br />  </span><span style="color: rgb(0, 0, 0);">34</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">35</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*//**</span><span style="color: rgb(0, 128, 0);"> <br />  36.      * We will insert Mock ActionForm for testing through this method <br />  37.      </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">38</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> ActionForm processActionForm(  <br />  </span><span style="color: rgb(0, 0, 0);">39</span><span style="color: rgb(0, 0, 0);">.         HttpServletRequest request,  <br />  </span><span style="color: rgb(0, 0, 0);">40</span><span style="color: rgb(0, 0, 0);">.         HttpServletResponse response,  <br />  </span><span style="color: rgb(0, 0, 0);">41</span><span style="color: rgb(0, 0, 0);">.         ActionMapping mapping) {  <br />  </span><span style="color: rgb(0, 0, 0);">42</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">43</span><span style="color: rgb(0, 0, 0);">.           <br />  </span><span style="color: rgb(0, 0, 0);">44</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Create (if necessary a form bean to use  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 0);">45</span><span style="color: rgb(0, 0, 0);">.         String formBeanName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mapping.getName();  <br />  </span><span style="color: rgb(0, 0, 0);">46</span><span style="color: rgb(0, 0, 0);">.         String mockBeanClassName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String) mockActionFormMap.get(formBeanName);  <br />  </span><span style="color: rgb(0, 0, 0);">47</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (mockBeanClassName </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)  <br />  </span><span style="color: rgb(0, 0, 0);">48</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.processActionForm(request, response, mapping);  <br />  </span><span style="color: rgb(0, 0, 0);">49</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">50</span><span style="color: rgb(0, 0, 0);">.         ActionForm instance </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;  <br />  </span><span style="color: rgb(0, 0, 0);">51</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {  <br />  </span><span style="color: rgb(0, 0, 0);">52</span><span style="color: rgb(0, 0, 0);">.             Class formClass </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Class.forName(mockBeanClassName );  <br />  </span><span style="color: rgb(0, 0, 0);">53</span><span style="color: rgb(0, 0, 0);">.             instance </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (ActionForm) formClass.newInstance();  <br />  </span><span style="color: rgb(0, 0, 0);">54</span><span style="color: rgb(0, 0, 0);">.         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (ClassNotFoundException e) {  <br />  </span><span style="color: rgb(0, 0, 0);">55</span><span style="color: rgb(0, 0, 0);">.             e.printStackTrace();  <br />  </span><span style="color: rgb(0, 0, 0);">56</span><span style="color: rgb(0, 0, 0);">.         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (InstantiationException e) {  <br />  </span><span style="color: rgb(0, 0, 0);">57</span><span style="color: rgb(0, 0, 0);">.             e.printStackTrace();  <br />  </span><span style="color: rgb(0, 0, 0);">58</span><span style="color: rgb(0, 0, 0);">.         } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IllegalAccessException e) {  <br />  </span><span style="color: rgb(0, 0, 0);">59</span><span style="color: rgb(0, 0, 0);">.             e.printStackTrace();  <br />  </span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">.         }  <br />  </span><span style="color: rgb(0, 0, 0);">61</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">62</span><span style="color: rgb(0, 0, 0);">.         instance.setServlet(servlet);  <br />  </span><span style="color: rgb(0, 0, 0);">63</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (instance </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {  <br />  </span><span style="color: rgb(0, 0, 0);">64</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">65</span><span style="color: rgb(0, 0, 0);">.         }  <br />  </span><span style="color: rgb(0, 0, 0);">66</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">67</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (log.isDebugEnabled()) {  <br />  </span><span style="color: rgb(0, 0, 0);">68</span><span style="color: rgb(0, 0, 0);">.             log.debug(  <br />  </span><span style="color: rgb(0, 0, 0);">69</span><span style="color: rgb(0, 0, 0);">.                 </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> Storing ActionForm bean instance in scope '</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">70</span><span style="color: rgb(0, 0, 0);">.                     </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> mapping.getScope()  <br />  </span><span style="color: rgb(0, 0, 0);">71</span><span style="color: rgb(0, 0, 0);">.                     </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">' under attribute key '</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">72</span><span style="color: rgb(0, 0, 0);">.                     </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> mapping.getAttribute()  <br />  </span><span style="color: rgb(0, 0, 0);">73</span><span style="color: rgb(0, 0, 0);">.                     </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">74</span><span style="color: rgb(0, 0, 0);">.         }  <br />  </span><span style="color: rgb(0, 0, 0);">75</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">request</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.equals(mapping.getScope())) {  <br />  </span><span style="color: rgb(0, 0, 0);">76</span><span style="color: rgb(0, 0, 0);">.             request.setAttribute(mapping.getAttribute(), instance);  <br />  </span><span style="color: rgb(0, 0, 0);">77</span><span style="color: rgb(0, 0, 0);">.         } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {  <br />  </span><span style="color: rgb(0, 0, 0);">78</span><span style="color: rgb(0, 0, 0);">.             HttpSession session </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> request.getSession();  <br />  </span><span style="color: rgb(0, 0, 0);">79</span><span style="color: rgb(0, 0, 0);">.             session.setAttribute(mapping.getAttribute(), instance);  <br />  </span><span style="color: rgb(0, 0, 0);">80</span><span style="color: rgb(0, 0, 0);">.         }  <br />  </span><span style="color: rgb(0, 0, 0);">81</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (instance);  <br />  </span><span style="color: rgb(0, 0, 0);">82</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">83</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">84</span><span style="color: rgb(0, 0, 0);">.   <br />  </span><span style="color: rgb(0, 0, 0);">85</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*//**</span><span style="color: rgb(0, 128, 0);"> <br />  86.      * We will insert Mock Action Class through this method <br />  87.      </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">88</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> Action processActionCreate(  <br />  </span><span style="color: rgb(0, 0, 0);">89</span><span style="color: rgb(0, 0, 0);">.         HttpServletRequest request,  <br />  </span><span style="color: rgb(0, 0, 0);">90</span><span style="color: rgb(0, 0, 0);">.         HttpServletResponse response,  <br />  </span><span style="color: rgb(0, 0, 0);">91</span><span style="color: rgb(0, 0, 0);">.         ActionMapping mapping)  <br />  </span><span style="color: rgb(0, 0, 0);">92</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> IOException {  <br />  </span><span style="color: rgb(0, 0, 0);">93</span><span style="color: rgb(0, 0, 0);">.         String orignalClassName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mapping.getType();  <br />  </span><span style="color: rgb(0, 0, 0);">94</span><span style="color: rgb(0, 0, 0);">.         String mockClassName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (String)mockActionMap.get(orignalClassName);  <br />  </span><span style="color: rgb(0, 0, 0);">95</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">( mockClassName </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> )  <br />  </span><span style="color: rgb(0, 0, 0);">96</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.processActionCreate(request,response,mapping);  <br />  </span><span style="color: rgb(0, 0, 0);">97</span><span style="color: rgb(0, 0, 0);">.         String className </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mockClassName;          <br />  </span><span style="color: rgb(0, 0, 0);">98</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (log.isDebugEnabled()) {  <br />  </span><span style="color: rgb(0, 0, 0);">99</span><span style="color: rgb(0, 0, 0);">.             log.debug(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> Looking for Action instance for class </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> className);  <br /> </span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 0);">.         }  <br /> </span><span style="color: rgb(0, 0, 0);">101</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">102</span><span style="color: rgb(0, 0, 0);">.         Action instance </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;  <br /> </span><span style="color: rgb(0, 0, 0);">103</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">synchronized</span><span style="color: rgb(0, 0, 0);"> (actions) {  <br /> </span><span style="color: rgb(0, 0, 0);">104</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">105</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Return any existing Action instance of this class  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">106</span><span style="color: rgb(0, 0, 0);">.             instance </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Action) actions.get(className);  <br /> </span><span style="color: rgb(0, 0, 0);">107</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (instance </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {  <br /> </span><span style="color: rgb(0, 0, 0);">108</span><span style="color: rgb(0, 0, 0);">.                 </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (log.isTraceEnabled()) {  <br /> </span><span style="color: rgb(0, 0, 0);">109</span><span style="color: rgb(0, 0, 0);">.                     log.trace(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">  Returning existing Action instance</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br /> </span><span style="color: rgb(0, 0, 0);">110</span><span style="color: rgb(0, 0, 0);">.                 }  <br /> </span><span style="color: rgb(0, 0, 0);">111</span><span style="color: rgb(0, 0, 0);">.                 </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (instance);  <br /> </span><span style="color: rgb(0, 0, 0);">112</span><span style="color: rgb(0, 0, 0);">.             }  <br /> </span><span style="color: rgb(0, 0, 0);">113</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">114</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> Create and return a new Action instance  </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">115</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (log.isTraceEnabled()) {  <br /> </span><span style="color: rgb(0, 0, 0);">116</span><span style="color: rgb(0, 0, 0);">.                 log.trace(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">  Creating new Action instance</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br /> </span><span style="color: rgb(0, 0, 0);">117</span><span style="color: rgb(0, 0, 0);">.             }  <br /> </span><span style="color: rgb(0, 0, 0);">118</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">119</span><span style="color: rgb(0, 0, 0);">.             </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {  <br /> </span><span style="color: rgb(0, 0, 0);">120</span><span style="color: rgb(0, 0, 0);">.                 instance </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Action) RequestUtils.applicationInstance(className);  <br /> </span><span style="color: rgb(0, 0, 0);">121</span><span style="color: rgb(0, 0, 0);">.             } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (Exception e) {  <br /> </span><span style="color: rgb(0, 0, 0);">122</span><span style="color: rgb(0, 0, 0);">.                 log.error(  <br /> </span><span style="color: rgb(0, 0, 0);">123</span><span style="color: rgb(0, 0, 0);">.                     getInternal().getMessage(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">actionCreate</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, mapping.getPath()),  <br /> </span><span style="color: rgb(0, 0, 0);">124</span><span style="color: rgb(0, 0, 0);">.                     e);  <br /> </span><span style="color: rgb(0, 0, 0);">125</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">126</span><span style="color: rgb(0, 0, 0);">.                 response.sendError(  <br /> </span><span style="color: rgb(0, 0, 0);">127</span><span style="color: rgb(0, 0, 0);">.                     HttpServletResponse.SC_INTERNAL_SERVER_ERROR,  <br /> </span><span style="color: rgb(0, 0, 0);">128</span><span style="color: rgb(0, 0, 0);">.                     getInternal().getMessage(  <br /> </span><span style="color: rgb(0, 0, 0);">129</span><span style="color: rgb(0, 0, 0);">.                         </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">actionCreate</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,  <br /> </span><span style="color: rgb(0, 0, 0);">130</span><span style="color: rgb(0, 0, 0);">.                         mapping.getPath()));  <br /> </span><span style="color: rgb(0, 0, 0);">131</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">132</span><span style="color: rgb(0, 0, 0);">.                 </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">);  <br /> </span><span style="color: rgb(0, 0, 0);">133</span><span style="color: rgb(0, 0, 0);">.             }  <br /> </span><span style="color: rgb(0, 0, 0);">134</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">135</span><span style="color: rgb(0, 0, 0);">.             instance.setServlet(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.servlet);  <br /> </span><span style="color: rgb(0, 0, 0);">136</span><span style="color: rgb(0, 0, 0);">.             actions.put(className, instance);  <br /> </span><span style="color: rgb(0, 0, 0);">137</span><span style="color: rgb(0, 0, 0);">.         }  <br /> </span><span style="color: rgb(0, 0, 0);">138</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">139</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> (instance);  <br /> </span><span style="color: rgb(0, 0, 0);">140</span><span style="color: rgb(0, 0, 0);">.     }  <br /> </span><span style="color: rgb(0, 0, 0);">141</span><span style="color: rgb(0, 0, 0);">.   <br /> </span><span style="color: rgb(0, 0, 0);">142</span><span style="color: rgb(0, 0, 0);">. }  </span></div>Test类：
<br />setUp()方法：
<br />  super.setUp();//调用mockStrutsTestCase中的setUp方法
<br />  File web = new File("E:/project/portal/WebContent");
<br />        this.setContextDirectory(web);//定位工程包的位置
<br />        setConfigFile("/WEB-INF/web.xml");//定位工程中的web.xml位置
<br />        setConfigFile("/WEB-INF/struts-config.xml");//定位工程中struts-config.xml位置
<br />        STCRequestProcessor.addMockActionForm("ser_wordForm", "test.sample.service.form.MockWordForm");//注入模拟的form
<br />
STCRequestProcessor.addMockAction("com.huawei.service.action.WordAction","test.sample.service.action.MockWordAction");//
注入模拟的action
<br />     setRequestPathInfo("/service/word");//定义struts-config.xml中的path名称<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test.sample.service.action;  <br />   </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">.   <br />   </span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">.   <br />   </span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.File;  <br />   </span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">.   <br />   </span><span style="color: rgb(0, 0, 0);">6</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> servletunit.struts.MockStrutsTestCase;  <br />   </span><span style="color: rgb(0, 0, 0);">7</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> test.sample.service.util.STCRequestProcessor;  <br />   </span><span style="color: rgb(0, 0, 0);">8</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*//**</span><span style="color: rgb(0, 128, 0);"> <br />   9.  *  <br />  10. -  setContextDirectory，设置web应用的根  <br />  11. -  setRequestPathInfo，设置request的请求  <br />  12. -  addRequestParameter，将参数和对应的值加入request中  <br />  13. -  actionPerform，执行这个请求  <br />  14. -  verifyForward，验证forward的名字是否正确  <br />  15. -  verifyForwardPath，验证forward的path是否正确  <br />  16. -  verifyNoActionErrors，验证在action执行过程中没有ActionError产生  <br />  17. -  verifyActionErrors，验证在action执行过程中产生的ActionError集合的内容  <br />  18.  * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> donganlei <br />  19.  * <br />  20.  </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);">  <br />  </span><span style="color: rgb(0, 0, 0);">21</span><span style="color: rgb(0, 0, 0);">. </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> MockWordActionTest </span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);"> MockStrutsTestCase {  <br />  </span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">.       <br />  </span><span style="color: rgb(0, 0, 0);">23</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testInvalidPageflag1()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{  <br />  </span><span style="color: rgb(0, 0, 0);">24</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">reqCode</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">getWordList</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">25</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pageflag</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">userquery</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">26</span><span style="color: rgb(0, 0, 0);">.           actionPerform();  <br />  </span><span style="color: rgb(0, 0, 0);">27</span><span style="color: rgb(0, 0, 0);">.           verifyNoActionErrors();  <br />  </span><span style="color: rgb(0, 0, 0);">28</span><span style="color: rgb(0, 0, 0);">.           verifyForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">querylist</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">29</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">30</span><span style="color: rgb(0, 0, 0);">.       <br />  </span><span style="color: rgb(0, 0, 0);">31</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testInvalidPageflag2()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{  <br />  </span><span style="color: rgb(0, 0, 0);">32</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">reqCode</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">getWordList</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">33</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pageflag</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">seatquery</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">34</span><span style="color: rgb(0, 0, 0);">.           actionPerform();  <br />  </span><span style="color: rgb(0, 0, 0);">35</span><span style="color: rgb(0, 0, 0);">.           verifyNoActionErrors();  <br />  </span><span style="color: rgb(0, 0, 0);">36</span><span style="color: rgb(0, 0, 0);">.           verifyForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">querylist</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">37</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">38</span><span style="color: rgb(0, 0, 0);">.       <br />  </span><span style="color: rgb(0, 0, 0);">39</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testInvalidInitUpdate()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{  <br />  </span><span style="color: rgb(0, 0, 0);">40</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">reqCode</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">initUpdate</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">41</span><span style="color: rgb(0, 0, 0);">.           actionPerform();  <br />  </span><span style="color: rgb(0, 0, 0);">42</span><span style="color: rgb(0, 0, 0);">.           verifyNoActionErrors();  <br />  </span><span style="color: rgb(0, 0, 0);">43</span><span style="color: rgb(0, 0, 0);">.           verifyForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">update</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">44</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">45</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> testinitUpdate()</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception{  <br />  </span><span style="color: rgb(0, 0, 0);">46</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">reqCode</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">initUpdate</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">47</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">wordid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">48</span><span style="color: rgb(0, 0, 0);">.           addRequestParameter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">roomid</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">49</span><span style="color: rgb(0, 0, 0);">.           actionPerform();  <br />  </span><span style="color: rgb(0, 0, 0);">50</span><span style="color: rgb(0, 0, 0);">.           verifyNoActionErrors();  <br />  </span><span style="color: rgb(0, 0, 0);">51</span><span style="color: rgb(0, 0, 0);">.           verifyForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">update</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">52</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">53</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">protected</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setUp() </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> Exception {  <br />  </span><span style="color: rgb(0, 0, 0);">54</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">super</span><span style="color: rgb(0, 0, 0);">.setUp();  <br />  </span><span style="color: rgb(0, 0, 0);">55</span><span style="color: rgb(0, 0, 0);">.         File web </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">E:/project/portal/WebContent</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">56</span><span style="color: rgb(0, 0, 0);">.         </span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.setContextDirectory(web);  <br />  </span><span style="color: rgb(0, 0, 0);">57</span><span style="color: rgb(0, 0, 0);">.         setConfigFile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/WEB-INF/web.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">58</span><span style="color: rgb(0, 0, 0);">.         setConfigFile(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/WEB-INF/struts-config.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">59</span><span style="color: rgb(0, 0, 0);">.         STCRequestProcessor.addMockActionForm(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">ser_wordForm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test.sample.service.form.MockWordForm</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">60</span><span style="color: rgb(0, 0, 0);">.         STCRequestProcessor.addMockAction(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">com.huawei.service.action.WordAction</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test.sample.service.action.MockWordAction</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">61</span><span style="color: rgb(0, 0, 0);">.         setRequestPathInfo(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/service/word</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">62</span><span style="color: rgb(0, 0, 0);">.     }  <br />  </span><span style="color: rgb(0, 0, 0);">63</span><span style="color: rgb(0, 0, 0);">.     </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String args[]){  <br />  </span><span style="color: rgb(0, 0, 0);">64</span><span style="color: rgb(0, 0, 0);">.         junit.textui.TestRunner.run(MockWordActionTest.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);  <br />  </span><span style="color: rgb(0, 0, 0);">65</span><span style="color: rgb(0, 0, 0);">.     }    <br />  </span><span style="color: rgb(0, 0, 0);">66</span><span style="color: rgb(0, 0, 0);">. }  </span></div>Struts-congfig.xml中的processorClass
<br /> &lt;controller&gt;
<br />      &lt;set-property property="processorClass" value="test.sample.service.util.STCRequestProcessor"/&gt;
<br /> &lt;/controller&gt;
    
  <br /><img src ="http://www.blogjava.net/colanlei/aggbug/215710.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-07-18 11:22 <a href="http://www.blogjava.net/colanlei/articles/215710.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于DBUnit的manage(Dao)单元测试</title><link>http://www.blogjava.net/colanlei/articles/215707.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Fri, 18 Jul 2008 03:20:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/articles/215707.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/215707.html</wfw:comment><comments>http://www.blogjava.net/colanlei/articles/215707.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/215707.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/215707.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: TestDBConnection父类 所有test类继承该类Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->   1. package test.sample.service.util;     2.      3. import java.io.Fi...&nbsp;&nbsp;<a href='http://www.blogjava.net/colanlei/articles/215707.html'>阅读全文</a><img src ="http://www.blogjava.net/colanlei/aggbug/215707.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-07-18 11:20 <a href="http://www.blogjava.net/colanlei/articles/215707.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>高效oracle查询</title><link>http://www.blogjava.net/colanlei/archive/2008/07/18/215705.html</link><dc:creator>人在旅途</dc:creator><author>人在旅途</author><pubDate>Fri, 18 Jul 2008 03:18:00 GMT</pubDate><guid>http://www.blogjava.net/colanlei/archive/2008/07/18/215705.html</guid><wfw:comment>http://www.blogjava.net/colanlei/comments/215705.html</wfw:comment><comments>http://www.blogjava.net/colanlei/archive/2008/07/18/215705.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/colanlei/comments/commentRss/215705.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/colanlei/services/trackbacks/215705.html</trackback:ping><description><![CDATA[1. 选用适合的ORACLE优化器 
<br />　　ORACLE的优化器共有3种: 
<br />　　a. RULE (基于规则) b. COST (基于成本) c. CHOOSE (选择性) 
<br />　　设置缺省的优化器,可以通过对init.ora文件中OPTIMIZER_MODE参数的各种声明,如RULE,COST,CHOOSE,ALL_ROWS,FIRST_ROWS . 你当然也在SQL句级或是会话(session)级对其进行覆盖. 
<br />　　为了使用基于成本的优化器(CBO, Cost-Based Optimizer) , 你必须经常运行analyze 命令,以增加数据库中的对象统计信息(object statistics)的准确性. 
<br />　　如果数据库的优化器模式设置为选择性(CHOOSE),那么实际的优化器模式将和是否运行过analyze命令有关. 如果table已经被analyze过, 优化器模式将自动成为CBO , 反之,数据库将采用RULE形式的优化器. 
<br />　　在缺省情况下,ORACLE采用CHOOSE优化器, 为了避免那些不必要的全表扫描(full table scan) , 你必须尽量避免使用CHOOSE优化器,而直接采用基于规则或者基于成本的优化器. 
<br />　　2. 访问Table的方式 
<br />　　ORACLE 采用两种访问表中记录的方式: 
<br />　　a. 全表扫描 
<br />　　全表扫描就是顺序地访问表中每条记录. ORACLE采用一次读入多个数据块(database block)的方式优化全表扫描. 
<br />　　b. 通过ROWID访问表 
<br />　　你可以采用基于ROWID的访问方式情况,提高访问表的效率, ,
ROWID包含了表中记录的物理位置信息..ORACLE采用索引(INDEX)实现了数据和存放数据的物理位置(ROWID)之间的联系.
通常索引提供了快速访问ROWID的方法,因此那些基于索引列的查询就可以得到性能上的提高. <br />　　3. 共享SQL语句 
<br />　　为了不重复解析相同的SQL语句,在第一次解析之后, ORACLE将SQL语句存放在内存中.这块位于系统全局区域SGA(system
global area)的共享池(shared buffer pool)中的内存可以被所有的数据库用户共享.
因此,当你执行一个SQL语句(有时被称为一个游标)时,如果它 和之前的执行过的语句完全相同,
ORACLE就能很快获得已经被解析的语句以及最好的执行路径. ORACLE的这个功能大大地提高了SQL的执行性能并节省了内存的使用. <br />　　可惜的是ORACLE只对简单的表提供高速缓冲(cache buffering) ,这个功能并不适用于多表连接查询. 
<br />　　数据库管理员必须在init.ora中为这个区域设置合适的参数,当这个内存区域越大,就可以保留更多的语句,当然被共享的可能性也就越大了. 
<br />　　当你向ORACLE 提交一个SQL语句,ORACLE会首先在这块内存中查找相同的语句. 
<br />　　这里需要注明的是,ORACLE对两者采取的是一种严格匹配,要达成共享,SQL语句必须完全相同(包括空格,换行等). 
<br />　　共享的语句必须满足三个条件: 
<br />　　A. 字符级的比较: 
<br />　　当前被执行的语句和共享池中的语句必须完全相同. 
<br />　　例如: 
<br />　　SELECT * FROM EMP; 
<br />　　和下列每一个都不同 
<br />　　SELECT * from EMP; 
<br />　　Select * From Emp; 
<br />　　SELECT * FROM EMP; 
<br />　　B. 两个语句所指的对象必须完全相同: 
<br />　　例如: 
<br />　　用户 对象名 如何访问 
<br />　　Jack sal_limit private synonym 
<br />　　Work_city public synonym 
<br />　　Plant_detail public synonym 
<br />　　Jill sal_limit private synonym 
<br />　　Work_city public synonym 
<br />　　Plant_detail table owner 
<br />　　考虑一下下列SQL语句能否在这两个用户之间共享. 
<br />　　SQL能否共享，原因 
<br />select max(sal_cap) from sal_limit; 
<br />　　不能。每个用户都有一个private synonym - sal_limit , 它们是不同的对象 
<br />　　select count(*0 from work_city where sdesc like 'NEW%'; 
<br />　　能。两个用户访问相同的对象public synonym - work_city 
<br />select a.sdesc,b.location from work_city a , plant_detail b where a.city_id = b.city_id 
<br />　　不能。用户jack 通过private synonym访问plant_detail 而jill 是表的所有者,对象不同. 
<br />　　C. 两个SQL语句中必须使用相同的名字的绑定变量(bind variables) 
<br />　　例如： 
<br />　　第一组的两个SQL语句是相同的(可以共享),而第二组中的两个语句是不同的(即使在运行时,赋于不同的绑定变量相同的值)
<br />　　a. 
<br />　　select pin , name from people where pin = :blk1.pin; 
<br />　　select pin , name from people where pin = :blk1.pin; 
<br />　　b. 
<br />　　select pin , name from people where pin = :blk1.ot_ind; 
<br />　　select pin , name from people where pin = :blk1.ov_ind;
<br /><br />　　4. 选择最有效率的表名顺序(只在基于规则的优化器中有效) 
<br />　　ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表 driving
table)将被最先处理. 在FROM子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表.当ORACLE处理多个表时,
会运用排序及合并的方式连接它们.首先,扫描第一个表(FROM子句中最后的那个表)并对记录进行派序,然后扫描第二个表(FROM子句中最后第二个
表),最后将所有从第二个表中检索出的记录与第一个表中合适记录进行合并. <br />　　例如: 
<br />　　表 TAB1 16,384 条记录 
<br />　　表 TAB2 1 条记录 
<br />　　选择TAB2作为基础表 (最好的方法) 
<br />select count(*) from tab1,tab2 执行时间0.96秒  
<br />　　选择TAB2作为基础表 (不佳的方法) 
<br />select count(*) from tab2,tab1 执行时间26.09秒  
<br />　　如果有3个以上的表连接查询, 那就需要选择交叉表(intersection table)作为基础表, 交叉表是指那个被其他表所引用的表. 
<br />　　例如: 
<br />　　EMP表描述了LOCATION表和CATEGORY表的交集. 
<br />SELECT * 
<br />FROM LOCATION L , 
<br />CATEGORY C, 
<br />EMP E 
<br />WHERE E.EMP_NO BETWEEN 1000 AND 2000 
<br />AND E.CAT_NO = C.CAT_NO 
<br />AND E.LOCN = L.LOCN  
<br />　　将比下列SQL更有效率 
<br />SELECT * 
<br />FROM EMP E , 
<br />LOCATION L , 
<br />CATEGORY C 
<br />WHERE E.CAT_NO = C.CAT_NO 
<br />AND E.LOCN = L.LOCN 
<br />AND E.EMP_NO BETWEEN 1000 AND 2000  
<br />　　5. WHERE子句中的连接顺序． 
<br />　　ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最大数量记录的条件必须写在WHERE子句的末尾. 
<br />　　例如: (低效,执行时间156.3秒) 
<br />SELECT … 
<br />FROM EMP E 
<br />WHERE SAL &gt; 50000 
<br />AND JOB = ‘MANAGER' 
<br />AND 25 &lt; (SELECT COUNT(*) FROM EMP 
<br />WHERE MGR=E.EMPNO);  
<br />　　(高效,执行时间10.6秒) 
<br />SELECT … 
<br />FROM EMP E 
<br />WHERE 25 &lt; (SELECT COUNT(*) FROM EMP 
<br />WHERE MGR=E.EMPNO) 
<br />AND SAL &gt; 50000 
<br />AND JOB = ‘MANAGER';  
<br />　　6. SELECT子句中避免使用 ‘ * ‘ 
<br />　　当你想在SELECT子句中列出所有的COLUMN时,使用动态SQL列引用 ‘*'
是一个方便的方法.不幸的是,这是一个非常低效的方法. 实际上,ORACLE在解析的过程中, 会将'*' 依次转换成所有的列名,
这个工作是通过查询数据字典完成的, 这意味着将耗费更多的时间. <br />　　7. 减少访问数据库的次数 
<br />　　当执行每条SQL语句时, ORACLE在内部执行了许多工作: 解析SQL语句, 估算索引的利用率, 绑定变量 , 读数据块等等. 由此可见, 减少访问数据库的次数 , 就能实际上减少ORACLE的工作量. 
<br />　　例如, 以下有三种方法可以检索出雇员号等于0342或0291的职员. 
<br />　　方法1 (最低效) 
<br />SELECT EMP_NAME , SALARY , GRADE 
<br />FROM EMP 
<br />WHERE EMP_NO = 342; 
<br />SELECT EMP_NAME , SALARY , GRADE 
<br />FROM EMP 
<br />WHERE EMP_NO = 291;  
<br />　　方法2 (次低效) 
<br />DECLARE 
<br />CURSOR C1 (E_NO NUMBER) IS 
<br />SELECT EMP_NAME,SALARY,GRADE 
<br />FROM EMP 
<br />WHERE EMP_NO = E_NO; 
<br />BEGIN 
<br />OPEN C1(342); 
<br />FETCH C1 INTO …,..,.. ; 
<br />….. 
<br />OPEN C1(291); 
<br />FETCH C1 INTO …,..,.. ; 
<br />CLOSE C1; 
<br />END;  
<br />　　方法3 (高效) 
<br />SELECT A.EMP_NAME , A.SALARY , A.GRADE, 
<br />B.EMP_NAME , B.SALARY , B.GRADE 
<br />FROM EMP A,EMP B 
<br />WHERE A.EMP_NO = 342 
<br />AND B.EMP_NO = 291;  
<br />　　注意: 
<br />　　在SQL*Plus , SQL*Forms和Pro*C中重新设置ARRAYSIZE参数, 可以增加每次数据库访问的检索数据量 ,建议值为200。
<br />　　8. 使用DECODE函数来减少处理时间 
<br />　　使用DECODE函数可以避免重复扫描相同记录或重复连接相同的表. 
<br />　　例如: 
<br />SELECT COUNT(*)，SUM(SAL) FROM　EMP 
<br />WHERE DEPT_NO = 0020 
<br />AND ENAME LIKE　‘SMITH%'; 
<br />SELECT COUNT(*)，SUM(SAL) 
<br />FROM　EMP 
<br />WHERE DEPT_NO = 0030 
<br />AND ENAME LIKE　‘SMITH%';  
<br />　　你可以用DECODE函数高效地得到相同结果 
<br />SELECT COUNT(DECODE(DEPT_NO,0020,'X',NULL)) D0020_COUNT, 
<br />COUNT(DECODE(DEPT_NO,0030,'X',NULL)) D0030_COUNT, 
<br />SUM(DECODE(DEPT_NO,0020,SAL,NULL)) D0020_SAL, 
<br />SUM(DECODE(DEPT_NO,0030,SAL,NULL)) D0030_SAL 
<br />FROM EMP WHERE ENAME LIKE ‘SMITH%';  
<br />　　类似的,DECODE函数也可以运用于GROUP BY 和ORDER BY子句中. 
<br />　　9. 整合简单,无关联的数据库访问 
<br />　　如果你有几个简单的数据库查询语句,你可以把它们整合到一个查询中(即使它们之间没有关系) 
<br />　　例如: 
<br />SELECT NAME FROM EMP 
<br />WHERE EMP_NO = 1234; 
<br />SELECT NAME FROM DPT 
<br />WHERE DPT_NO = 10 ; 
<br />SELECT NAME FROM CAT 
<br />WHERE CAT_TYPE = ‘RD';  
<br />　　上面的3个查询可以被合并成一个: 
<br />SELECT E.NAME , D.NAME , C.NAME FROM CAT C , DPT D , EMP E,DUAL X 
<br />WHERE NVL(‘X',X.DUMMY) = NVL(‘X',E.ROWID(+)) 
<br />AND NVL(‘X',X.DUMMY) = NVL(‘X',D.ROWID(+)) 
<br />AND NVL(‘X',X.DUMMY) = NVL(‘X',C.ROWID(+)) 
<br />AND E.EMP_NO(+) = 1234 
<br />AND D.DEPT_NO(+) = 10 
<br />AND C.CAT_TYPE(+) = ‘RD';  
<br />　　(译者按: 虽然采取这种方法,效率得到提高,但是程序的可读性大大降低,所以读者 还是要权衡之间的利弊) 
<br />　　10. 删除重复记录 
<br />　　最高效的删除重复记录方法 ( 因为使用了ROWID) 
<br />DELETE FROM EMP E 
<br />WHERE E.ROWID &gt; (SELECT MIN(X.ROWID) 
<br />FROM EMP X 
<br />WHERE X.EMP_NO = E.EMP_NO);  
<br />　　11. 用TRUNCATE替代DELETE 
<br />　　当删除表中的记录时,在通常情况下, 回滚段(rollback segments ) 用来存放可以被恢复的信息.
如果你没有COMMIT事务,ORACLE会将数据恢复到删除之前的状态(准确地说是恢复到执行删除命令之前的状况) ，而当运用TRUNCATE时,
回滚段不再存放任何可被恢复的信息.当命令运行后,数据不能被恢复.因此很少的资源被调用,执行时间也会很短。(注：
TRUNCATE只在删除全表适用,TRUNCATE是DDL不是DML) <br />　　12. 尽量多使用COMMIT 
<br />　　只要有可能,在程序中尽量多使用COMMIT, 这样程序的性能得到提高,需求也会因为COMMIT所释放的资源而减少: 
<br />　　COMMIT所释放的资源: 
<br />　　a. 回滚段上用于恢复数据的信息. 
<br />　　b. 被程序语句获得的锁 
<br />　　c. redo log buffer 中的空间 
<br />　　d. Oracle为管理上述3种资源中的内部花费 
<br />　　(注：在使用COMMIT时必须要注意到事务的完整性,现实中效率和事务完整性往往是鱼和熊掌不可得兼) 
<br />　　如果DECODE取值为NULL，SUM（NULL）的值是NULL --&gt;如果所有的值都是NULL , SUM(NULL) = NULL 但是只要有一个值不是NULL,SUM() &lt;&gt; NULL 所以原SQL应该没有什么逻辑上的问题 
<br />　　关于第八点的个人看法：如果DECODE取值为NULL，SUM（NULL）的值是NULL，不会正常求和的。可以改成如下所示就好了：
SELECT COUNT(DECODE(DEPT_NO,0020,'X',NULL)) D0020_COUNT,
COUNT(DECODE(DEPT_NO,0030,'X',NULL)) D0030_COUNT,
SUM(DECODE(DEPT_NO,0020,SAL,0)) D0020_SAL,
SUM(DECODE(DEPT_NO,0030,SAL,0)) D0030_SAL FROM EMP WHERE ENAME LIKE
‘SMITH%';<img src ="http://www.blogjava.net/colanlei/aggbug/215705.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/colanlei/" target="_blank">人在旅途</a> 2008-07-18 11:18 <a href="http://www.blogjava.net/colanlei/archive/2008/07/18/215705.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>