<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 使用annotation定义数据库事务,这样可以在类或方法中直接使用@Transactional注解来声明事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
2.使用事务管理器来管理
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<!-- 切入点指明了在执行com.zxt.service包中的所有方法时产生事务拦截 *** 作 -->
<aop:pointcut id="daoMethods"
expression="execution(* com.zxt.service.*.*(..))" />
<!-- 定义了将采用何种拦截 *** 作,这里引用到 txAdvice -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods" />
</aop:config>
<!-- 事务通知 *** 作,使用的事务管理器引用自transactionManager -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 指定哪些方法需要加入事务 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<!-- read-only="true":其余方法只读格式,加强其安全性 -->
<tx:method name="*" read-only="true" propagation="NOT_SUPPORTED" />
</tx:attributes>
</tx:advice>
</beans>
很多朋友想用sql2000数据库的编程方法,但是却又苦于自己是学access的,对sql只是一点点的了解而已,这里我给大家提供以下参考---将access转化成sql2000的方法和注意事项一,首先,我说的是在access2000,sql2000之间转换,其他的我也还没有尝试过,希望大家多多试验,肯定是有办法的;
二,转换的方法
1,打开”控制面板“下”管理工具“中的”数据库源“;
2,按”添加“添加一个新的数据源,在选择栏里选“driver
do
microsoft
access
(*.mdb)”,完成后将出现一个框,在“数据库源”里面输入你想写的名称,我取名叫“abc”,说明不需要填,接着,按下面的选择,寻找你的数据库地址和选中(注意,请先备份自己的access数据库),然后确定。数据源在这里建好了,剩下转换了。
3,打开sql2000企业管理器,进入数据库,新建一个空的数据库“abc”;
4,选择新建立的数据库,按鼠标右键,选择“所有任务”下“导入数据”,按“下一步”继续;
5,在数据库源下拉但中选择”driver
do
microsoft
access(*.mdb)“,在”用户/系统dsn“中,选种你刚才添加的”abc“,按
”下一步“;
6,“目的”不需要修改,选择服务器(一般下为自己的本机local,也可以选择服务器地址或者局域网地址,确定你的权限是否可以 *** 作,),使用windows
身份验证指用自己的系统管理员身份 *** 作,使用sql身份 *** 作验证可以用于网站的 *** 作,推荐用后者
7,选上使用sql身份 *** 作验证后,填写你的用户名和密码,我自己选择的是系统默认号码sa,****,数据库选择刚新建的abc,按下一步
8,这一步的两个单项选择,从数据源复制表和视图与用一条查询指令指定要传输的数据,选择前者,按下一步继续
9,这里将出现你自己access数据库的表,按全选后,下一步
10,dts导入/导出向导,看立即运行被选中按下一步,
11,按完成继续
12,这个步骤你将看到你的数据被导入sql2000里面,当出现已经成功把xxx个表导入到数据库的字样,而且所有的表前面都有绿色的勾,就表示成功导入所有数据,如果中途出现问题或者表前面有红色的叉的话,说明该表没有成功导入,这时就要回去查看自己的 *** 作是否正确了.
三,数据修改
1,由于sql2000里面没有自动编号,所以你的以自动编号设置的字段都会变成非空的字段,这就必须手工修改这些字段,并把他的标示选择是,种子为1,增量为1,
2,另外,access2000转换成sql2000后,原来属性为是/否的字段将被转换成非空的bit,这时候你必须修改成自己想要的属性了
3,另外,大家要注意对时间函数的把握.access与sql是有很多不同的.
access转ms
sql数据库的几点经验
1.access的数据库中的自动编号类型在转化时,sql
server并没有将它设为自动编号型,我们需在sql创建语句中加上identity,表示自动编号!
2.转化时,跟日期有关的字段,sql
server默认为smalldatetime型,我们最好将它变为datetime型,因为datetime型的范围比smalldatetime型大。我遇见这种情况,用smalldatetime型时,转化失败,而用datetime型时,转化成功。
3.对此两种数据库进行 *** 作的sql语句不全相同,例如:在对access数据库进行删除纪录时用:delete
*
from
user
where
id=10,而对sql
server数据库进行删除是用:delete
user
where
id=10.
4.日期函数不相同,在对access数据库处理中,可用date()、time()等函数,但对sql
server数据库处理中,只能用datediff,dateadd等函数,而不能用date()、time()等函数。
5.在对access数据库处理中,sql语句中直接可以用一些vb的函数,像cstr()函数,而对sql
server数据库处理中,却不能用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)