摘要: 持久化单元,持久化对象的集合。事务类型:本地事务和全局事务。某些应用场合,只能使用全局事务。有两个数据库,mysql和oracle.转账时扣钱从mysql进行,加钱是在oracle执行,怎样确保两个语句在同一个事务中执行。普通JDBC不能,只能用全局事务。事务的生命周期应该从Connection对象中抽取出来,不应该局限在Connection中。通常由容器(WebLogic,JBoss)提供JTA实现。二次提交协议,执行一条语句预提交到数据库,执行结果保存到某个变量中,再执行另一条语句,如果都成功,再进行第二次提交。类路径下META-INF/persistence.xml如下:<?xml 阅读全文
posted @ 2012-01-04 09:25 tazi 阅读(1008) 评论(0) 推荐(0) 编辑
摘要: 1.odbc方式2.jdbc驱动包方式public static void main(String[] args) { try { //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Class.forName("oracle.jdbc.driver.OracleDriver"); //Connection con=DriverManager.getConnection("jdbc:odbc:scott", "scott", "123456"); C 阅读全文
posted @ 2012-01-04 09:23 tazi 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1.加上Context命名空间xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation加上http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"2.要使用注解方式,进行依赖注入。要加上@Resource等注解的解析器<context:annotation-config/>3.要 阅读全文
posted @ 2012-01-04 09:22 tazi 阅读(841) 评论(0) 推荐(0) 编辑
摘要: 使用Hibernate 1.Hibernate核心包 hibernate-distribution-3.31.GA hibernate3.jar lib/bytecode/cglib/hiber... 阅读全文
posted @ 2012-01-04 09:21 tazi 阅读(342) 评论(2) 推荐(0) 编辑
摘要: <?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframewor 阅读全文
posted @ 2011-12-30 15:21 tazi 阅读(1167) 评论(0) 推荐(0) 编辑
摘要: JdbcTemplate jdbcTemplate==new JdbcTemplate(source);//传入DataSource类型的参数它封装了jdbc中Connection对象的取得,Statement对象的建立,异常的处理,Statement和Connection的关闭等操作。它是线程安全的。如:jdbcTemplate.update("delete from person where id=?", new Object[]{id}, new int[]{Types.INTEGER});其中第三个参数可以省略。或者使用PreparedStatementCreato 阅读全文
posted @ 2011-12-30 15:19 tazi 阅读(593) 评论(0) 推荐(0) 编辑
摘要: 1.Spring单个连接的数据源为<bean id="simpleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost: 阅读全文
posted @ 2011-12-30 14:49 tazi 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 不用在配置文件中配置Bean,使Bean交给容器管理。1.加入context命名空间<context:component-scan base-package="com.service"/>此配置加入了很多相关的注解处理器。也包括<context:annotation-config/>所对应的处理器。2.定义base-package,使Spring自动扫描该包以及所有子包中的所有的标注了某些注解的类。3.在类上根据类的作用分别用@Service(业务层)、@Controller,@Repository(DAO层),@Component(通用)4.get 阅读全文
posted @ 2011-12-30 12:23 tazi 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 注入依赖对象有手工装配(推荐)和自动装配的方式。手工装配可在xml中,也可用注解方式。1.Setter2.构造器方式1 <bean id="pDao" class="PersonDaoBean"/>2 <bean id="ps" class="PersonServiceBean">3 <constructor-arg index="0" type="PersonDao" ref="pDao"/>4 <constru 阅读全文
posted @ 2011-12-30 10:22 tazi 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 1.Bean的作用域默认Bean的作用域是singleton,另外还有prototype(每次都创建新的实例)2.Bean什么时候被创建singleton类型的Bean默认是在Spring容器启动时创建,prototype在getBean时创建可以修改这种行为:在<bean>中的lazy-init="default","false","true"或者在<beans >属性default-lazy-init="false"3.Bean初始化时执行某个方法 init-method="& 阅读全文
posted @ 2011-12-30 08:38 tazi 阅读(252) 评论(0) 推荐(0) 编辑