影子,一沓一沓的影子
鸡零狗碎 or 片羽吉光
1,老者的自述
年岁不饶人,青丝变白条。老气横秋,气短神衰。
人老而经验不老,人老而教训也丰。人老而智慧不足,人老而谋略不彰。一日一日,人愈老则愈与自身南辕北辙矣。
Oracle中删除表中相同记录的分析
Oracle中删除表中相同记录的分析
分两种情况:
1,删除所有字段均相同的行:
create table tablexxx as (select * from tableyyy group by col1,col2,col3…)
drop table tableyyy
create table tableyyy as (select * from tablexxx)
drop table tablexxx
2,表中有id列,删除另一字段name取值相同的行:
delete b where id not in
(
select min(id) from B
group by name
)
Oracle序列的(Sequence)使用
我对Log4J的一点初认识
Java的开源项目太多太多了。这种遍地开花的局面绝对赶得上中国五代十国时期的“百家争鸣”、“百花争艳”的繁荣。使用java技术,我们的项目几乎不需要购买有关java支撑开发产品,只需把一个一个开源产品经过架构师的手,合理搭配和拼接,就能做出灵活性佳、性能不错的商业产品来。
无疑, 作为一个流行的日志记录工具,Log4j是java开源项目中最闪亮的环节之一。笔者所见的java项目,十九都采用了Log4j,究其原因,我认为有以下几点:
a)Log4j受大多数web应用服务器的拥护:以我目前所知,tomcat,weblogic,websphere,jboss都支持log4j。
b)快速,功能强大:Log4J配置文件实现了输出到控制台、文件、回滚文件、发送日志邮件、输出到数据库日志表、自定义标签等全套功能。在速度上,从log4j一开始出现,注重运行的速度就一直放在首位,并且坚持不懈地进行着改进和完善。
c)使用简单、方便:只需要导入一个简单的log4j-1.2.x.jar,然后在程序类的开头写上下面一句private final static Logger log =Logger.getLogger(ClassName.class);
这样你就得到了一个日志对象log,可以轻松往特定目标写日志了。
原始的方法是:把信息输出到屏幕(console),利用JDK提供的System.out.println。但是,这样做的坏处是显而易见的:
a)信息的输出不够灵活,并且繁琐。比如,要输出执行处的文件名,行数,当前时间等,println显得很原始。
b)如果要改变输出的内容和格式,需要重新编译源程序。
c)更严重的是,如果程序中有很多的println,会严重的影响程序的性能。
??根记录器(Logger),输出端(appenders)和布局(layouts)
log4j.rootLogger = [ level ], appendName1, appendName2, …appendNameN。同一个记录器可有多个输出端。
PS:level的级别(此级别可以自定义,系统默认提供了以下级别)
◆debug//调试信息
◆info//一般信息
◆warn//警告信息
◆error//错误信息
◆fatal//致命错误信息
上面列出的就是所谓log4j的输出级别,log4j建议只使用4个级别,它们从上到下分别为ERROR、WARN、INFO、DEBUG,假设你定义的级别是info,那么error和warn的日志可以显示而比他低的debug信息就不显示了。
log4j.appender.appenderName = fully.qualified.name.of.appender.class。log4j提供了以下几种常用的输出目的地:
◆org.apache.log4j.ConsoleAppender,将日志信息输出到控制台
◆org.apache.log4j.FileAppender,将日志信息输出到一个文件
◆org.apache.log4j.DailyRollingFileAppender,将日志信息输出到一个,并且每天输出到一个新的日志文件
◆org.apache.log4j.RollingFileAppender,将日志信息输出到一个文件,通过指定文件的的尺寸,当文件大小到达指定尺寸的时候会自动把文件改名,如名为example.log的文件会改名为
example.log.1,同时产生一个新的example.log文件。如果新的文件再次达到指定尺寸,又会自动把文件改名为 example.log.2,同时产生一个example.log文件。依此类推,直到example.log. MaxBackupIndex, MaxBackupIndex的值可在配置文件中定义。
◆org.apache.log4j.WriterAppender,将日志信息以流格式发送到任意指定的地方。
◆org.apache.log4j.jdbc.JDBCAppender,通过JDBC把日志信息输出到数据库中。
Log4j提供了一下几种布局:
◆org.apache.log4j.HTMLLayout,以HTML表格形式布局
◆org.apache.log4j.PatternLayout,可以灵活地指定布局模式
◆org.apache.log4j.SimpleLayout,包含日志信息的级别和信息字符串
定义一个PatternLayout布局的语句为:
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1} - %m%n
PS:ConversionPattern参数的格式含义
格式名 含义
%c 输出日志信息所属的类的全名
%d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,比如:%d{yyy-MM-dd HH:mm:ss },输出类似:
%f 输出日志信息所属的类的类名
%l 输出日志事件的发生位置,即输出日志信息的语句处于它所在的类的第几行
%m 输出代码中指定的信息,如log(message)中的message
%n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL。如果是调用debug()输出的,则为DEBUG,依此类推
%r 输出自应用启动到输出该日志信息所耗费的毫秒数
%t 输出产生该日志事件的线程名
◆在程序中调用BasicConfigurator.configure()方法;
◆配置放在文件里,通过命令行参数传递文件名字,通过
PropertyConfigurator.configure(args[x])解析并配置;
◆配置放在文件里,通过环境变量传递文件名等信息,利用log4j默认的初始化过程解析并配置;
◆配置放在文件里,通过应用服务器配置传递文件名等信息,利用一个特殊的servlet来完成配置。
通过应用服务器完成初始化
通过servlet辅助完成初始化
log4j.rootLogger=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=/webserver/specialTraining3/wangzj.log
log4j.appender.logfile.MaxFileSize=51200KB
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
Web.xml文件:
version="1.0" encoding="ISO-8859-1"?>
web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD
Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
Log4j.properties文件:
log4j.rootLogger=DEBUG, ROOT
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
log4j.appender.ROOT.File=E:\wangzj\myapplication.log
log4j.appender.ROOT.MaxFileSize=1000KB
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
ootLogger=DEBUG,CONSOLE,A1,im
log4j.addivity.org.apach
MyModel.java文件:
package com.webage.model;
import org.apache.log4j.Logger;
public class MyModel {
static Logger logger = Logger.getLogger(MyModel.class);;
public void checkValid(String name, String value) throws Exception {
logger.debug("ENTRY");
logger.debug("检查参数: " + name);
if (value == null) {
throw new Exception("缺少参数。");
}
if (value.trim().length() == 0) {
throw new Exception("参数空。");
}
logger.debug("EXIT");
}
}
MyServlet.java
package com.webage.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.webage.model.MyModel;
public class MyServlet extends HttpServlet {
Logger logger = Logger.getLogger(MyServlet.class);
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
logger.debug("ENTRY");
MyModel model = new MyModel();
resp.getWriter().println("Log4J测试
");
try {
model.checkValid("firstName", req.getParameter("firstName"));
} catch (Exception e) {
logger.error("doGet出现错误.", e);
}
logger.debug("EXIT");
}
public void init() throws ServletException {
super.init();
logger.info("Servlet初始化...");
}
}
需要两个jar包:servlet.jar和log4j-
准备就绪,运行之于tomcat或者weblogic,笔者暂用weblogic代之。每当运行Logger logger = Logger.getLogger(MyServlet.class);时即生成E:\wangzj\myapplication.log文件。
Happy~~~~!
log4j.rootLogger=DEBUG,CONSOLE,A1,im
log4j.addivity.org.apache=true
# 应用于控制台
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.Threshold=DEBUG
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD] n%c[CATEGORY]%n%m[MESSAGE]%n%n
#应用于文件
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=file.log //相对路径和绝对路径
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
# Use this layout for LogFactor 5 analysis
# 应用于文件回滚
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLING_FILE.Threshold=ERROR
log4j.appender.ROLLING_FILE.File=rolling.log
log4j.appender.ROLLING_FILE.Append=true
log4j.appender.ROLLING_FILE.MaxFileSize=10KB
log4j.appender.ROLLING_FILE.MaxBackupIndex=1
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
#应用于socket
log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender
log4j.appender.SOCKET.RemoteHost=localhost
log4j.appender.SOCKET.Port=5001
log4j.appender.SOCKET.LocationInfo=true
# Set up for Log Facter 5
log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout
log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%n
# Log Factor 5 Appender
log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender
log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000
# 发送日志给邮件
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.Threshold=FATAL
log4j.appender.MAIL.BufferSize=10
log4j.appender.MAIL.From=web@www.wuset.com
log4j.appender.MAIL.SMTPHost=www.wusetu.com
log4j.appender.MAIL.Subject=Log4J Message
log4j.appender.MAIL.To=web@www.wusetu.com
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
# 用于数据库
log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DATABASE.URL=jdbc:mysql://localhost:3306/test
log4j.appender.DATABASE.driver=com.mysql.jdbc.Driver
log4j.appender.DATABASE.user=root
log4j.appender.DATABASE.password=
log4j.appender.DATABASE.sql=INSERT INTO LOG4J (Message) VALUES ('[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n')
log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout
log4j.appender.DATABASE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=SampleMessages.log4j
log4j.appender.A1.DatePattern=yyyyMMdd-HH'.log4j'
log4j.appender.A1.layout=org.apache.log4j.xml.XMLLayout
#自定义Appender
log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender
log4j.appender.im.host = mail.cybercorlin.net
log4j.appender.im.username = username
log4j.appender.im.password = password
log4j.appender.im.recipient = corlin@cybercorlin.net
log4j.appender.im.layout=org.apache.log4j.PatternLayout
log4j.appender.im.layout.ConversionPattern =[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
已锁定
- 作者: wangnewton 2005年08月16日, 星期二 17:46 回复(1) | 引用(0)
Velocity例子学习
- 作者: wangnewton 2005年08月12日, 星期五 15:36 回复(0) | 引用(0)
一个web.xml示例
一个web.xml示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>dump</servlet-name>
<display-name>DataDump</display-name>
<servlet-class>course.demo.servlet.DataDump</servlet-class>
</servlet>
<servlet>
<servlet-name>exam</servlet-name>
<display-name>ControllerServlet</display-name>
<servlet-class>hys.exam.servlet.ControllerServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>forum</servlet-name>
<servlet-class>org.apache.velocity.demo.ControllerServlet</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>WEB-INF/velocity.properties</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dump</servlet-name>
<url-pattern>/dump</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>exam</servlet-name>
<url-pattern>/exam</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>forum</servlet-name>
<url-pattern>forum</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/WEB-INF/sslext.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/sslext.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-template.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
<resource-ref id="ResourceRef_1112438789750">
<res-ref-name>jdbc/hysh</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
- 作者: wangnewton 2005年08月9日, 星期二 14:15 回复(0) | 引用(0)
struts-config.xml示例文件
- 作者: wangnewton 2005年08月8日, 星期一 12:50 回复(0) | 引用(0)
翻译文档(2005-8-8)
http://publishblog.blogdriver.com/blog/tb.b?diaryID=855297
翻译文档:
What
will PROFInet provide?
These things cause the open
style standard to suit to automation based on the
ethernet.
Today automated technology is
receiving day by day influences by the information technology(IT),which has
already established standards(for example TCP/IP and
XML).
Author: Peter
Wenzel
Because the information
technology in the automated integration, appears many improvements between the
automated system the mailing addresss, affects the profound disposition and the
diagnosis no matter what chooses with the network scope service function
together, is now developing.
From the beginning of these
characteristics,they are the PROFInet’s holistic
part.
PROFInet is the open style
standard of Profrbss international (PI), it based on the industry ethernet, and
being used in the industrial automation. The distributional automated
implementation, the existing dispersible scene equipment integration, is
complex, first considered the time factor the application procedure movement
(for example movement control), to PROFInet said all is no
problem.
Besides being used in IT,
PROFInet also plays a vital role in protection investments. PROFInet can
integrate the existing field bus system, like profibos do not need to change the
existing equipments. Thus has protected the system, machine equipment
manufacturer’s investments.
PROFInet absolutely satisfies
the automated technology all requests. Has used the experience in the PROFInet
standard which in the Profibos environment for many years has accumulated. The
open style standard as well as equipments existing partial simple processing and
the integration, from as soon as start had determined PROFInet the
definition.
As a result of the PROFInet
unceasing further development, provides the long-term prospect for the users.
Regarding the equipment or the machine manufacturers that, using PROFInet to be
possible to make the smallest cost which the installment, the project and goes
into production. And to the system runners, because of each part of system is
apart, so the system expansion will more convinenet and could guarantee that has
the high level useable to the system.
Because PI has established a
set of authentication procedures, thus can guarantee the PROFInet products the
high grade standard.
PROFInet phase
of development:
PROFInet’s first edition was
promoted in spring,2001, it involved the part model, with the TCP/IP standard
communications, as well as in the system scope the project which has nothing to
do with with the dealers.
Thus, except question and so
on outside network management and integration, PROFInet starts to indicate the
real-time communication the important topic. The PROFInet real-time solution’s
first step is promotes "Soft Real Time" (SRT). May achieve 5 with it to the 10ms
cycle time. With these functions, PROFInet satisfies all models request which in
the production automation realizes.
In March, 2003 PI started the
second real-time phase of exploitation. The isochronism real-time solution (IRT)
satisfies the related performance and the clock synchronization complex
movement, the control application procedure request. The 1ms cycle time and is
smaller than the 1ms vibration, are most may control 150 axes to use IRT, the
PROFInet choice "five kind of ethernets", with it may achieve very many
equipment and the very wide range network, protects the user and the
manufacturer characteristic, the movement control uses, based on Profibus
PROFIdrive guild regulations, in fact has not made the modification to implement
in PROFInet.
The PROFInet integration
solution’s biggest merit lies in its communication openness and scaleable.
PROFInet
functional scope
The opening automated standard
PROFInet stipulation function permission implementation whole automation
solution, its scope matches the network installment and the project from the
equipment and the system which buys for use, until production base and based on
when World Wide Web's diagnosis movement corresponds. The PROFInet modular
structure makes it to be specially easy to implement including the multi-purpose
expansion. The existing field bus application procedure integration is carries
on with the agent concept.
PROFInet is first based on the
open ethernet system, provides one kind the project connection which has nothing
to do with with the dealer. Through the equipment between correspondence
connection graph disposition, permits in an independent system, the simple
integration the equipment and the part which produces by the different
manufacturer.
The automated technology development has caused the
modular equipment and the machine. Is precisely because this kind of structure
provides drive. Urges the automated technology further to develop, establishes
the distributional automated system. For this goal, PROFInet provides one kind
of solution, equipment each part decomposes Cheng Gezhong the technology
module.