??xml version="1.0" encoding="utf-8" standalone="yes"?> 1Q用Spring ?ActionSupport 无论用那U方法来整合W一步就是要为struts来装载spring的应用环境?是?struts 中加入一个插件?br />
struts-config.xml?/p>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> 1Q用Spring的ActionSupport . q是一?servlet 的代码: applicationContext.xml 中的配置 q中配置方式同直接在web.xml文g配置差别不大。注意:Actionl承?org.springframework.web.struts.ActionSupport 使得struts和spring耦合在一赗?br />
但实C表示层和业务逻辑层的解?LoginDao dao = (LoginDao) ctx.getBean("loginDao"))?/p>
public class LoginAction extends Action { public LoginDao getDao() { public ActionForward execute(ActionMapping mapping, ActionForm form, q里 name="/login" 与struts 中的path匚w q要?LoginAction 提供必要的setXXXҎ?获得ApplicationCotext和依赖注入的工作都在DelegatingRequestProcessor中完成?/p>
</form-beans> <global-exceptions /> type="org.springframework.web.struts.DelegatingActionProxy" > <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> </struts-config> 2Q?Lstruts-config.xml?<controller > 三种整和方式中我们优先选用 全权委托的方式?br />
理由Q?br />
1Q第一U得过多的耦合了Spring和Action . ȝ一下: 本文转自Q?a >http://blog.csdn.net/caoyinghui1986/archive/2008/06/02/2501914.aspx 隔离U别定义了事务与事务之间的隔ȝ度?/p>
隔离U别与ƈ发性是互ؓ矛盾的:隔离E度高Q数据库的ƈ发性越差;隔离E度低Q数据库的ƈ发性越好?/p>
ANSI/ISO SQ92标准定义了一些数据库操作的隔ȝ别: 通过一些现象,可以反映出隔ȝ别的效果。这些现象有Q?/p>
下面是隔ȝ别及其对应的可能出现或不可能出现的现?/p>
ORACE的隔ȝ?/strong> ORACE提供了SQ92标准中的read committed和seriaizabeQ同时提供了非SQ92标准的read-ony?/p>
read committedQ?/strong> seriaizabeQ(串行执行事务Qƈ发性最) 如果有在seriaizabe事务开始时未提交的事务在seriaizabe事务l束之前修改了seriaizabe事务要修改的行q进行了提交Q则seriaizabe事务不会dq些变更Q因此发生无法序列化讉K的错误。(换一U解释方法:只要在seriaizabe事务开始到l束之间有其他事务对seriaizabe事务要修改的东西q行了修改ƈ提交了修改,则发生无法序列化讉K的错?/strong>。) If a serializable transaction contains data manipulation language (DML) that attempts to update any resource that may have been updated in a transaction uncommitted at the start of the serializable transaction, Qƈ且修改在后来被提交而没有回滚)Qthen the DML statement fails. q回的错误是ORA-08177: Cannot serialize access for this transaction?/p>
ORACE在数据块中记录最q对数据行执行修Ҏ作的N个事务的信息Q目的是定本事务开始时Q是否存在未提交的事务修改了本事务将要修改的行。具体见英文Q?/p>
Oracle permits a serializable transaction to modify a data row only if it can determine that prior changes to the row were made by transactions that had committed when the serializable transaction began. To make this determination efficiently, Oracle uses control information stored in the data block that indicates which rows in the block contain committed and uncommitted changes. In a sense, the block contains a recent history of transactions that affected each row in the block. The amount of history that is retained is controlled by the INITRANS parameter of CREATE TABLE and ALTER TABLE. Under some circumstances, Oracle may have insufficient history information to determine whether a row has been updated by a "too recent" transaction. This can occur when many transactions concurrently modify the same data block, or do so in a very short period. You can avoid this situation by setting higher values of INITRANS for tables that will experience many transactions updating the same blocks. Doing so will enable Oracle to allocate sufficient storage in each block to record the history of recent transactions that accessed the block. The INITRANS ParameterQOracle stores control information in each data block to manage access by concurrent transactions. Therefore, if you set the transaction isolation level to serializable, you must use the ALTER TABLE command to set INITRANS to at least 3. This parameter will cause Oracle to allocate sufficient storage in each block to record the history of recent transactions that accessed the block. Higher values should be used for tables that will undergo many transactions updating the same blocks. read-onyQ?/strong> read committed和seriaizabe的区别和联系Q?/strong> 事务1先于事务2开始,q保持未提交状态。事?惌修改正被事务1修改的行。事?{待。如果事?回滚Q则事务2Q不论是read committedq是seriaizabe方式Q进行它惌做的修改。如果事?提交Q则当事?是read committed方式Ӟq行它想要做的修改;当事?是seriaizabe方式Ӟp|q报?#8220;Cannot seriaize access”Q因Z?看不见事?提交的修改,且事?惛_事务1修改的基上再做修攏V?/p>
即seriaizabe不允许存在事务嵌?/p>
具体见英文: Both read committed and serializable transactions use row-level locking, and both will wait if they try to change a row updated by an uncommitted concurrent transaction. The second transaction that tries to update a given row waits for the other transaction to commit or roll back and release its lock. If that other transaction rolls back, the waiting transaction (regardless of its isolation mode) can proceed to change the previously locked row, as if the other transaction had not existed. However, if the other (blocking) transaction commits and releases its locks, a read committed transaction proceeds with its intended update. A serializable transaction, however, fails with the error "Cannot serialize access", because the other transaction has committed a change that was made since the serializable transaction began. read committed和seriaizabe可以在ORACEq行服务器中使用?/p>
关于SET TRANSACTION READ WRITEQread write和read committed 应该是一L。在L面,它们都避免了脏读Q但都无法实现重复读。虽然没有文档说明read write在写斚w与read committed一_但显然它在写的时候会加排他锁以避免更C失。在加锁的过E中Q如果遇到待锁定资源无法锁定Q应该是{待而不是放弃。这?read committed一致?/p>
语句U的M致?/p>
事务U的M致?/p>
讄隔离U别 讄一个事务的隔离U别 讄增个会话的隔ȝ?/p>
Application designers and developers should choose an isolation level based on application performance and consistency needs as well as application coding requirements. For environments with many concurrent users rapidly submitting transactions, designers must assess transaction performance requirements in terms of the expected transaction arrival rate and response time demands. Frequently, for high-performance environments, the choice of isolation levels involves a trade-off between consistency and concurrency. For many applications, read committed is the most appropriate isolation level. Read committed isolation can provide considerably more concurrency with a somewhat increased risk of inconsistent results due to phantoms and non-repeatable reads for some transactions. Many high-performance environments with high transaction arrival rates require more throughput and faster response times than can be achieved with serializable isolation. Other environments that supports users with a very low transaction arrival rate also face very low risk of incorrect results due to phantoms and nonrepeatable reads. Read committed isolation is suitable for both of these environments. 两种情况Q(1Q在事务量大、高性能的计环境,需要更高的吞吐量和响应旉Q(2Q事务数,q且发生qd和不可重复读的几率的比较?/p>
Oracle read committed isolation provides transaction set consistency for every query. That is, every query sees data in a consistent state. Therefore, read committed isolation will suffice for many applications that might require a higher degree of isolation if run on other database management systems that do not use multiversion concurrency control. Read committed isolation mode does not require application logic to trap the "Cannot serialize access" error and loop back to restart a transaction. In most applications, few transactions have a functional need to issue the same query twice, so for many applications protection against phantoms and non-repeatable reads is not important. Therefore many developers choose read committed to avoid the need to write such error checking and retry code in each transaction. Oracle's serializable isolation is suitable for environments where there is a relatively low chance that two concurrent transactions will modify the same rows and the long-running transactions are primarily read-only. It is most suitable for environments with large databases and short transactions that update only a few rows. Q?Q适合于很存在两个事务同时修改同一条记录的情况 Q?Q长事务以只Mؓ?/p>
Q?Q大型数据库q且每个短事务只修改很少的记?/p>
Serializable isolation mode provides somewhat more consistency by protecting against phantoms and nonrepeatable reads and can be important where a read/write transaction executes a query more than once. Unlike other implementations of serializable isolation, which lock blocks for read as well as write, Oracle provides nonblocking queries and the fine granularity of row-level locking, both of which reduce write/write contention. For applications that experience mostly read/write contention, Oracle serializable isolation can provide significantly more throughput than other systems. Therefore, some applications might be suitable for serializable isolation on Oracle but not on other systems. All queries in an Oracle serializable transaction see the database as of a single point in time, so this isolation level is suitable where multiple consistent queries must be issued in a read/write transaction. A report-writing application that generates summary data and stores it in the database might use serializable mode because it provides the consistency that a
值得研究一?br />
2, 使用Spring ?DelegatingRequestProcessor cR?br />
3Q全权委托?/p>
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
</plug-in>
spring 的配|文件被作ؓ参数配置q来。这样可以省略对web.xml 文g中的配置?span style="color: #ff0000">保你的applicationContext.xml 在WEB-INF目录下面
Spring 的ActionSupport l承?org.apache.struts.action.Action
ActionSupport的子cd以或?WebApplicationContextcd的全局变量。通过getWebApplicationContext()可以获得q个变量?/p>
public class LoginAction extends org.springframework.web.struts.ActionSupport {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
//获得 WebApplicationContext 对象
WebApplicationContext ctx = this.getWebApplicationContext();
LoginDao dao = (LoginDao) ctx.getBean("loginDao");
User u = new User();
u.setName(loginForm.getName());
u.setPwd(loginForm.getPwd());
if(dao.checkLogin(u)){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
}
<beans>
<bean id="loginDao" class="com.cao.dao.LoginDao"/>
</beans>
2,使用Spring ?DelegatingRequestProcessor c?/strong>
DelegatingRequestProcessor l承?org.apache.struts.action.RequestProcessor q覆盖了里面的方法?br />
sturts-config.xml ?nbsp; <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> 通过 <controller >来替?br />
org.apache.struts.action.RequestProcessor 的请求处理?/p>
//利用spring来注入这个对象?br />
private LoginDao dao ;
public void setDao(LoginDao dao) {
System.out.println("执行注入");
this.dao = dao;
}
return dao;
}
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
//q样一改这行代码似乎没有必要了?br />
//WebApplicationContext ctx = this.getWebApplicationContext();
//LoginDao dao = (LoginDao) ctx.getBean("loginDao");
User u = new User();
u.setName(loginForm.getName());
u.setPwd(loginForm.getPwd());
//直接用dao来调用spring会将q个对象实例化?br />
if(dao.checkLogin(u)){
return mapping.findForward("success");
}else{
return mapping.findForward("error");
}
}
}
q里的?br />
LoginAction extends Action 说明 struts 每有和spring 耦合?br />
看一?br />
applicationContext.xml 中的配置?br />
<beans>
<bean id="loginDao" class="com.cao.dao.LoginDao"/>
<bean name="/login" class="com.cao.struts.action.LoginAction">
<property name="dao">
<ref local="loginDao"/>
</property>
</bean>
</beans>
class="com.cao.struts.action.LoginAction" 与struts 中的type匚w
3Q全权委托:
Action 的创建和对象的依赖注入全部由IOC容器来完成?使用Spring的DelegatingAcionProxy来帮助实C理的工作
org.springframework.web.struts.DelegatingActiongProxyl承于org.apache.struts.action.Action .
全权委托的配|方式同 方式 2 cM (applcationContext.xml文g的配|和 Actioncȝ实现方式相同)?br />
<struts-config>
<data-sources />
<form-beans >
<form-bean name="loginForm" type="com.cao.struts.form.LoginForm" />
<global-forwards />
<action-mappings >
<!-- type指向的是spring 的代理类 -->
<action
attribute="loginForm"
input="login.jsp"
name="loginForm"
path="/login"
scope="request"
<forward name="success" path="/ok.jsp" />
<forward name="error" path="/error.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.cao.struts.ApplicationResources" />
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
</plug-in>
不同之处
1Q?<action>?type指向的是spring 的代理类
2,RequestProcessorcdl被代理 如果要再实现自己的实现方式(如:~码处理Q怕有炚w烦?/p>
整合工作中的步骤Q?br />
1Q修改struts-config.xml
2, 配置applicationContext.xml
3, 为Actiondget/setҎ 来获得依赖注入的功能?/p>
Spring声明式事务管理源码解M事务开?http://www.javaeye.com/topic/87426
Spring声明式事务管理源码解M事务提交 http://www.javaeye.com/topic/88189
然后再读时不需要加锁,q一点Oracle的共享锁的实C上一中的共享锁原理有点不同Q?/strong>
今天在查看oracle官方文档lock的那一部分的时候发C个新的概念,isolation level (数据隔离U别)Q虽然以前学q,但是忘的差不多了?br />
隔离U别Qisoation eveQ?/strong>
Dirty Read
NonRepeatabe Read
Phantom Read
Read uncommitted
Possible
Possible
Possible
Read committed
not possible
Possible
Possible
Repeatabe read
not possible
not possible
Possible
Seriaizabe
not possible
not possible
not possible
Choice of Isolation Level
Read Committed Isolation
Serializable Isolation
READ
ONLY
transaction provides, but also allows INSERT
, UPDATE
, and DELETE
.
name VARCHAR2(10) --姓名
create table student (ID char(6), name VARCHAR2(100));
insert into sale values('200001',‘张一’);
insert into sale values('200002',‘王二’);
insert into sale values('200003',‘李三’);
insert into sale values('200004',‘赵四’);
commit;
(1) rownum 对于{于某值的查询条g
如果希望扑ֈ学生表中W一条学生的信息Q可以用rownum=1作ؓ条g。但是想扑ֈ学生表中W二条学生的信息Q用rownum=2l果查不到数据。因为rownum都是?开始,但是1以上的自然数在rownum做等于判断是时认为都是false条gQ所以无法查到rownum = nQn>1的自然数Q?br />
SQL> select rownum,id,name from student where rownum=1;Q可以用在限制返回记录条数的地方Q保证不出错Q如Q隐式游标)
SQL> select rownum,id,name from student where rownum=1;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
1 200001 张一
SQL> select rownum,id,name from student where rownum =2;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
Q?Qrownum对于大于某值的查询条g
如果xCW二行记录以后的记录Q当使用rownum>2是查不出记录的,原因是由于rownum是一个L?开始的伪列QOracle 认ؓrownum> n(n>1的自然数)q种条g依旧不成立,所以查不到记录
SQL> select rownum,id,name from student where rownum >2;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
那如何才能找到第二行以后的记录呀。可以用以下的子查询方法来解决。注意子查询中的rownum必须要有别名Q否则还是不会查录来Q这是因为rownum不是某个表的列,如果不v别名的话Q无法知道rownum是子查询的列q是L询的列?br />
SQL>select * from(select rownum no ,id,name from student) where no>2;
NO ID NAME
---------- ------ ---------------------------------------------------
3 200003 李三
4 200004 赵四
SQL> select * from(select rownum,id,name from student)where rownum>2;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
Q?Qrownum对于于某值的查询条g
如果x到第三条记录以前的记录,当用rownum<3是能得到两条记录的。显然rownum对于rownum<nQ?n>1的自然数Q的条g认ؓ是成立的Q所以可以找到记录?br />
SQL> select rownum,id,name from student where rownum <3;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
1 200001 张一
2 200002 王二
lg几种情况Q可能有时候需要查询rownum在某区间的数据,那怎么办呀从上可以看出rownum对小于某值的查询条g是h为true的,rownum对于大于某值的查询条g直接认ؓ是false的,但是可以间接的让它{为是true的。那必M用子查询。例如要查询rownum在第二行到第三行之间的数据,包括W二行和W三行数据,那么我们只能写以下语句,先让它返回小于等于三的记录行Q然后在L询中判断新的rownum的别名列大于{于二的记录行。但是这L操作会在大数据集中媄响速度?br />
SQL> select * from (select rownum no,id,name from student where rownum<=3 ) where no >=2;
NO ID NAME
---------- ------ ---------------------------------------------------
2 200002 王二
3 200003 李三
Q?Qrownum和排?br />
Oracle中的rownum的是在取数据的时候生的序号Q所以想Ҏ定排序的数据L定的rowmun行数据就必须注意了?br />
SQL> select rownum ,id,name from student order by name;
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
3 200003 李三
2 200002 王二
1 200001 张一
4 200004 赵四
可以看出Qrownumq不是按照name列来生成的序受系l是按照记录插入时的序l记录排的号Qrowid也是序分配的。ؓ了解册个问题,必须使用子查?br />
SQL> select rownum ,id,name from (select * from student order by name);
ROWNUM ID NAME
---------- ------ ---------------------------------------------------
1 200003 李三
2 200002 王二
3 200001 张一
4 200004 赵四
q样成了按name排序Qƈ且用rownum标出正确序号Q有到大)
W者在工作中有一上百万条记录的表Q在jsp面中需对该表进行分|C, 便考虑用rownum来作Q下面是具体Ҏ(每页
昄20?Q?
“select * from tabname where rownum<20 order by name" 但却发现oracle却不能按自己的意愿来执行Q而是先随?br />
?0条记录,然后?order byQ后l咨询oracle,说rownum实pP想用的话Q只能用子查?来实现先排序Q后
rownumQ方法如下:
"select * from (select * from tabname order by name) where rownum<20",但这样一来,效率会较低很多?
后经W者试验,只需在order by 的字D上加主键或索引卛_让oracle先按 该字D|序,然后再rownumQ方法不变:
“select * from tabname where rownum<20 order by name"
取得某列中第N大的?/p>
select column_name from
(select table_name.*,dense_rank() over (order by column desc) rank from table_name)
where rank = &NQ?
假如要返回前5条记录:
select * from tablename where rownum<6;(或是rownum <= 5 或是rownum != 6)
假如要返回第5-9条记录:
select * from tablename
where …
and rownum<10
minus
select * from tablename
where …
and rownum<5
order by name
选出l果后用name排序昄l果?先选再排序)
注意Q只能用以上W号(<?lt;=?=)?/p>
select * from tablename where rownum != 10;q回的是前9条记录?
不能用:>,>=,=,Between...and。由于rownum是一个L?开始的伪列QOracle 认ؓq种条g 不成立,查不到记?
另外Q这个方法更快:
select * from (
select rownum r,a from yourtable
where rownum <= 20
order by name )
where r > 10
q样取出W?1-20条记?(先选再排序再?
要先排序再选则ȝselect嵌套Q内层排序外层选?
rownum是随着l果集生成的Q一旦生成,׃会变化了Q同?生成的结果是依次递加的,没有1永q不会有2!
rownum 是在 查询集合产生的过E中产生的伪列,q且如果where条g中存?rownum 条g的话Q则:
1Q?假如 判定条g是常量,则:
只能 rownum = 1, <= 大于1 的自然数Q?= 大于1 的数是没有结果的Q?大于一个数也是没有l果?
?当出C?rownum 不满x件的时候则 查询l束 this is stop key!
2: 当判定g是常量的时?
若条件是 = var , 则只有当 var ? 的时候才满条gQ这个时候不存在 stop key ,必须q行 full scan ,Ҏ个满_他where条g的数据进行判?
选出一行后才能去选rownum=2的行……
Q?Q回?日志。DELETE语句执行删除的过E是每次从表中删除一行,q且同时该行的的删除操作作Z务记录在日志中保存以便进行进行回滚操作。TRUNCATE TABLE 则一ơ性地从表中删除所有的数据ƈ不把单独的删除操作记录记入日志保存,删除行是不能恢复的。ƈ且在删除的过E中不会ȀzM表有关的删除触发器。执行速度快?/p>
Q?Q表和烦引所占空间。当表被TRUNCATE 后,q个表和索引所占用的空间会恢复到初始大,而DELETE操作不会减少表或索引所占用的空间?/p>
Q?Q应用范围。TRUNCATE 只能对TABLEQDELETE可以是table,view,synonym
Q?QTRUNCATE 和DELETE只删除数据,而DROP则删除整个表Q结构和数据Q?
Q?QTRUNCATE 是DDLQDELETE是DML?/p>
truncate、deleteQ不带where子句Q与drop的异同点Q?br />
相同之处Q?br />
三者均会删除表内的data?br />
不同点:
<1>、truncate与不带where的delete Q只删除数据Q而不删除表的l构Q定义)
drop语句删除表的结构被依赖的约束(constrain),触发器(trigger), 索引Qindex);依赖于该表的存储q程/函数被保留Q但其状态会变ؓQinvalid?br />
<2>、delete语句为DMLQdata maintain Language),q个操作会被攑ֈ rollback segment?事务提交后才生效。如果有相应?tigger,执行的时候将被触发?br />
truncate、drop是DLLQdata define language),操作立即生效Q原数据不放?rollback segment中,不能回滚Q操作不触发 trigger?br />
<3>、delete语句不媄响表所占用?extentQ段Q?高水U(high watermark)保持原位|不动?br />
drop语句表所占用的空间全释放掉?br />
truncate语句~省情况下将I间释放?minextents ?extent,除非使用 renuse storage;truncate 会将高水U?high watermark)复位Q回到最初位|)?br />
<4>、速度Q?br />
一般而言Qdrop > truncate > delete?br />
<5>、安全性:
在没有备份情况下Q}慎?drop ?truncate。要删除部分数据行采?delete且注意结合where来约束媄响范围。回滚段要够大。要删除表用drop;若想保留表而将表中数据删除Q如果于事务无关Q用truncate卛_实现。如果和事务有关Q或老师惌发trigger,q是用delete?br />
如果是整理表内部的碎片,可以用truncateq结合reuse storage,再重新导?插入数据?br />
附Microsoft SQL
Truncate是SQL中的一个删除数据表内容的语句,用法是:
TRUNCATE TABLE [Table Name]?br />
下面是对Truncate语句在MSSQLServer2000中用法和原理的说明:
Truncate table 表名 速度?而且效率?因ؓ:
truncate table 在功能上与不?WHERE 子句?DELETE 语句相同Q二者均删除表中的全部行。但 TRUNCATE TABLE ?DELETE 速度快,且用的pȝ和事务日志资源少?
DELETE 语句每次删除一行,q在事务日志中ؓ所删除的每行记录一VTRUNCATE TABLE 通过释放存储表数据所用的数据|删除数据Qƈ且只在事务日志中记录늚释放?
TRUNCATE TABLE 删除表中的所有行Q但表结构及其列、约束、烦引等保持不变。新行标识所用的计数值重|ؓ该列的种子。如果想保留标识计数|h?DELETE。如果要删除表定义及其数据,请?DROP TABLE 语句?
对于?FOREIGN KEY U束引用的表Q不能?TRUNCATE TABLEQ而应使用不带 WHERE 子句?DELETE 语句。由?TRUNCATE TABLE 不记录在日志中,所以它不能Ȁz触发器?
TRUNCATE TABLE 不能用于参与了烦引视囄?/p>
//主键549830479
alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新?49830479
alter table t2 add d timestamp;
alter table infos add ex tinyint not null default '0';
//删除?49830479
alter table t2 drop column c;
//重命名列549830479
alter table t1 change a b integer;
//改变列的cd549830479
alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default '0';
//重命名表549830479
alter table t1 rename t2;
加烦?49830479
mysql> alter table tablename change depno depno int(5) not null;
mysql> alter table tablename add index 索引?(字段?[Q字D名2 …]);
mysql> alter table tablename add index emp_name (name);
加主关键字的索引549830479
mysql> alter table tablename add primary key(id);
加唯一限制条g的烦?49830479
mysql> alter table tablename add unique emp_name2(cardnumber);
删除某个索引549830479
mysql>alter table tablename drop index emp_name;
修改表:549830479
增加字段Q?49830479
mysql> ALTER TABLE table_name ADD field_name field_type;
修改原字D名U及cdQ?49830479
mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
删除字段Q?49830479
mysql> ALTER TABLE table_name DROP field_name;
mysql 常用增删Ҏ命定
关键? mysql增删Ҏ
插入一条记?
mysql> insert into table_name (column_name1,column_name2,.) values (value1,value2,..);
更新一条记录:
mysql> update tbl_name
set col_name1=expr1 [, col_name2=expr2 ...][WHERE where_definition]
[ORDER BY ...][LIMIT row_count];
删除一条记录:
mysql>delete from table_name where id=XX;
删除整个表的数据Q?
mysql> drop from table_name;
查询一条记录:
mysql>select * from table_name where id=XX;
mysql中删除部分重复记录的Ҏ
关键? mysql中删除部分重复记?
假设person表中有三个字D?分别是id(自增) name age 部分记录中的name ,age出现重复
比如
id name age
1 zhangsan 20
2 zhangsan 20
3 lisi 25
4 lisi 25
1 ,2 部分重复Q?,4也是部分重复 Q现在四条记录我只保留不重复的两条。删除方法如下:
1.按name,age分组查询出所有不重复的idq放入到tmp表中
create table tmp select min(id) as id from person group by name,age;
2.Ҏ上面查询出的id号从person表中查询出所有的数据q放到表tmp2?
create table tmp2 select person.* from person,tmp where person.id = tmp.id;
3.删除person?
drop table person;
4.把tmp2重命名ؓperson
rename table tmp2 to person;
需求要求实现用弹出层发送邮件。提交后层关闭,E序再服务器端响应?/p>
JSON插g提供了一U名为json的ResultTypeQ一旦ؓ某个Action指定了一个类型ؓjson的ResultQ则该Result无需映射CQ何视图资源。因为JSON插g会负责将Action里的状态信息序列化成JSON格式的数据,q将该数据返回给客户端页面的JavaScript ?/p>
单地_JSON插g允许我们在JavaScript中异步调用ActionQ而且Action不再需要用视图资源来昄该Action里的状态信息,而是由JSON插g负责Action里的状态信息返回给调用面——通过q种方式Q就可以完成Ajax交互?br />
1、将struts2的json插g加入web工程的libQjsonplugin的下载地址Q?a target="_blank">http://code.google.com/p/jsonplugin/downloads/list
2、struts.xmld专ؓajax使用的package
<package name="ajax" extends="json-default">
<action name="ajaxRequest" class="org.david.struts2.HelloWorld">
<result type="json"></result>
</action>
</package>
3、在面中引?nbsp;jquery的js文g?/span>
<SCRIPT type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<SCRIPT type="text/javascript">
function clickButton()
{
var url = 'ajaxRequest.action';
var params = {
name:$('#name').attr('value'),
contactEmail:$('#contactEmail').attr('value'),
subject:$('#subject').attr('value'),
content:$('#content').attr('value')
}; //通过id获得输入?br />
jQuery.post(url, params, callbackFun, 'json');
} //urlQ响应acitonQparamsQ传入参敎ͼcallbackFunQ响应完成后的回调函敎ͼ
function callbackFun(data)
{
alert("SUCCESS");
}
</SCRIPT>
4、action逻辑与普通的ation写法无大区别?/span>
JSONAction里的状态信息序列化成JSON格式的数?/span>