- 浏览: 1076355 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (453)
- Struts2 (30)
- Spring (14)
- iBATIS (6)
- Hibernate (13)
- JVM (5)
- JSON (10)
- Ajax (5)
- Flex (1)
- JavaScript (25)
- PowerDesigner (4)
- 项目管理 (7)
- 数据库 (29)
- 生活 (18)
- 软件应用 (21)
- 无线技术 (2)
- Linux (39)
- TOP开发学习 (2)
- JAVA工具小TIPS (2)
- Java通用 (52)
- XML (3)
- 软件测试 (29)
- Maven (10)
- Jquery (1)
- 正则表达式 (3)
- 应用服务器 (15)
- Android (5)
- linux 和windowx 下 tomcat 设置JVM (8)
- 应用服务器 连接池 (4)
- Linux 后台输出中文乱码 (1)
- Hadoop (28)
- python (2)
- Kafka (7)
- Storm (5)
- Elasticsearch (7)
- fddd (1)
最新评论
-
kafodaote:
Kafka分布式消息系统实战(与JavaScalaHadoop ...
分布式消息系统Kafka初步 -
小灯笼:
LoadRunner性能测试实战课程网盘地址:http://p ...
LoadRunner性能测试应用(八) -
成大大的:
Kafka分布式消息系统实 ...
分布式消息系统Kafka初步 -
hulalayaha2:
Loadrunner性能测试视频教程下载学习:http://p ...
LoadRunner性能测试应用(八) -
993042835:
搞好 谢谢
org.hibernate.exception.ConstraintViolationException: could not delete:
spring + struts + hibernate 数据源的几种配置方法
环境:JDK 1.6 + tomcat 6.0 + spring2.5 + struts2.18 + hibernate3.x
1. c3p0数据连接池 (需要将mysql-connector-java-5.0.8-bin.jar文件copy到tomcat 的lib下)
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
- <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入
-->
<context:component-scan base-package="cn.com.zqk" />
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=gbk" />
- <property name="properties">
- <props>
<prop key="c3p0.minPoolSize">2</prop>
<prop key="c3p0.maxPoolSize">100</prop>
<prop key="c3p0.timeout">5000</prop>
<prop key="c3p0.max_statement">100</prop>
<prop key="c3p0.testConnectionOnCheckout">true</prop>
- <!-- 获取connnection时测试是否有效
-->
<prop key="c3p0.testConnectionOnCheckin">true</prop>
- <!-- 自动测试的table名称
-->
<prop key="c3p0.automaticTestTable">t_wb_zqk</prop>
- <!-- set to something much less than wait_timeout, prevents connections from going stale
-->
<prop key="c3p0.idleConnectionTestPeriod">18000</prop>
- <!-- set to something slightly less than wait_timeout, preventing 'stale' connections from being handed out
-->
<prop key="c3p0.maxIdleTime">25000</prop>
<prop key="user">root</prop>
<prop key="password">123456</prop>
- <!-- set to 'SELECT 1'
-->
<prop key="validationQuery">SELECT 1</prop>
- <!-- set to 'true'
-->
<prop key="testWhileIdle">true</prop>
- <!-- some positive integer
-->
<prop key="timeBetweenEvictionRunsMillis">3600000</prop>
- <!-- set to something smaller than 'wait_timeout'
-->
<prop key="minEvictableIdleTimeMillis">18000000</prop>
- <!-- if you don't mind a hit for every getConnection(), set to "true"
-->
<prop key="testOnBorrow">true</prop>
</props>
</property>
</bean>
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
- <property name="mappingDirectoryLocations">
- <list>
<value>classpath:/cn/com/zqk/model/</value>
</list>
</property>
- <property name="hibernateProperties">
- <value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- <!-- hibernate.hbm2ddl.auto=update
-->
hibernate.show_sql=false hibernate.format_sql=true
</value>
</property>
</bean>
- <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
- <!-- 使用基于注解方式配置事务
-->
<tx:annotation-driven transaction-manager="txManager" />
</beans>
2. JNDI + proxoolDB 连接池(需要将mysql-connector-java-5.0.8-bin.jar,proxool-0.9.1.jar,proxool-cglib.jar文件copy到tomcat 的lib下)
第一步:在tomcat/conf/context.xml中配置JDNI
<Resource name="jdbc/jndiname"
auth="Container"
type="javax.sql.DataSource"
factory="org.logicalcobwebs.proxool.ProxoolDataSource"
proxool.alias="proxoolDB"
user="root"
password="123456"
delegateProperties="foo=1,bar=true"
proxool.jndi-name="jndiname"
proxool.driver-url="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GBK"
proxool.driver-class="com.mysql.jdbc.Driver"
proxool.house-keeping-sleep-time="900000"
proxool.maximum-active-time="5"
proxool.prototype-count="3"
proxool.statistics="1m,15m,1d"
proxool.simultaneous-build-throttle="10"
proxool.minimum-connection-count="5"
proxool.maximum-connection-count="100"
proxool.house-keeping-test-sql="select * from t_wb_zqk"
proxool.test-before-use="true"/>
第二步:applicationContext.xml 中配置数据源
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="cn.com.zqk" />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/jndiname</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/cn/com/zqk/model/</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
<!-- hibernate.hbm2ddl.auto=update -->
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.cache.use_query_cache = true
hibernate.cache.provider_class = org.hibernate.cache.EhCacheProvider
hibernate.cache.use_second_level_cache = true
<!-- hibernate.connection.release_mode = after_statement -->
</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!--使用基于注解方式配置事务 -->
<tx:annotation-driven transaction-manager="txManager" />
</beans>
个人签名
-------------------------------------
发表评论
-
Spring的自动任务中调用业务类方法
2012-03-21 15:18 1401Spring 中使用 QuartzJobBean 来进行定 ... -
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
2011-08-02 12:46 2069我在使用Struts2进行开发的时候老是报下面的错误: 严重: ... -
Hibernate 批量插入、更新与删除 转
2011-03-08 17:10 3537批量插入 在项目 ... -
hibernate 批量插入的测试 转
2011-03-08 17:02 1061Hibernate 批量插入的测试:最近在项目中做了一个充值卡 ... -
org.hibernate.exception.ConstraintViolationException: could not delete:
2010-12-21 17:57 5092转发的。 解决异常org.hibernate.exce ... -
Hibernate 使用缓存时,数据同步问题。
2010-10-14 17:14 4078教一下hibernate缓存如何 ... -
Hibernate中用hql查询部分字段
2010-10-02 16:24 2434Hibernate中用hql查询部分字段 SEL ... -
could not initialize proxy - no Session
2010-09-02 15:09 3215原文地址:http://www.wozaishuo.com.c ... -
hibernate 的缓存使用问题 转
2010-06-10 10:01 941hibernate 的缓存使用问题 悬赏:5 发布时间:20 ... -
spring中配置hibernate缓存
2010-06-09 17:24 940spring中配置hibernate缓存 JAVA学习 20 ... -
hibernate查询缓存 转
2010-06-09 16:39 1168hibernate查询缓存 收藏 【hibernate查询缓 ... -
org.hibernate.exception.JDBCConnectionException: could not execute query
2010-04-30 13:57 10858Hibernate MySql 连接池隔天断开解决方法 ...
相关推荐
(1)该项目是基于spring3+struts2+hibernate3+spring security3的权限管理项目 (2)后台我已经实现了权限管理,包括用户,角色和资源的分配。前台实现了spring security3的管理 (3)网上案例普遍是后台单一登陆。...
基于三大框架架构Spring+Struts2+Hibernate 这个是我毕业设计,有论文,也有答辩ppt,开题报告... 比较成功,所以传上来与大家分享。 界面采用新浪界面样式, 后台层次非常清晰。 数据库采用MySql。 服务器用tomcat...
spring 3.29+struts2.3.15.1+hibernate3 动态切换数据源
struts2+spring4+hibernate4整合时所用的所有jar包,包括c3p0数据源jar包
5.单数据源配置(兼容Tomcat和Weblogic)。 6.Hibernate继承 HibernateDaoSupport。 7.Spring+Junit4单元测试,优点:不会破坏数据库现场,等等。 2)Demo 导入说明: 1.Eclipse Encoding:GBK 2.Eclipse 导入后可能...
开发技术:Spring3.2,Struts2.3,Hibernate3,bootstrap样式,bootstrap脚本,jquery脚本,layer弹窗组件,ueditor富文本框,webuploader文件上传组件,echarts图表展示组件等技术; 二、项目说明 本系统实现了...
(1) 提供支持三种数据源方案:C3P0、DBCP、JNDI,三选一,请注释或删除其他方案 (2) 提取四种Hibernate整合方案:四选一,请注释或删除其他方案 (3) 提供两种声明式事务管理器方案:二选一,请注释或删除其他...
MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在...
SSH整合学习笔记之struts2+spring+hibernate+c3p0源码
项目申报系统是一个基于Struts2+Spring+Hibernate+Jsp+Mysql5的计算机专业JSP源码资料包。这个资料包包含了一个完整的项目申报系统的源代码,适用于计算机专业的学习与实践。首先,该系统采用了经典的SSH框架,即...
java开发图片投票系统(struts+spring+hibernate)+mysql数据库,在eclipse3.2环境下开发,项目我已经压缩,内包括数据库sql脚本和测试数据脚本,可以部署在eclipse下继续开发或学习源代码或采用的技术框架,web发布...
5、tomcate数据源配置 见 tomcat配置.txt //这个项目用不着了 6、创建了专门的数据库操作工具类 DBUtil、专门的DAO管理工具DAOManager 7、实现了CRUD的基本操作 8、struts2基本标签的使用 9、struts2的Action实现,...
实现查询和插入,并有建表sql,tomcat数据源配置说明
图书管理系统是一个基于Struts+Hibernate+Spring+Ext的计算机专业JSP源码资料包,它为开发者提供了一套完整的图书管理解决方案。这个系统采用了经典的MVC架构,将业务逻辑、数据访问和界面展示分离,使得代码结构...
数据库新建:test 字符:UTF-8,本地如果有test数据库,最好删掉,以免表关联导致数据不对 数据库帐号和密码都没有加密,自己去数据库查,为了方便大家学习 工程导入,字符记得也要改成UTF-8 密码修改文件为:...
上网找资料,都是一些不全的. struts2+extjs2.1+json+hibernate+spring 自己整合的例子. 当中hibernate数据源可以配置自己的.后台输送json 前台接收.
业务流程清晰,权限控制非常完善,功能齐全,提供源代码和大量数据库测试数据.在页面的布局美观,数据访问上做了大量优化,执行效率很高,另赠JS日历控件,分页标签库,EHCache缓存等使用工具及其使用方法.由于上传限制,未将...
-- 数据源配置,在生产环境使用应用服务器的数据库连接池 --> <!-- <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/store" />--> <!--Hibernate配置--> ...
Spring多数据源配置_分布式数据 Tomcat服务器下的多数据源配置详情 一、环境及框架 Tomcat+spring+hibernate+jotm,还有就是struts、Oracle等 二、需求说明 系统里有2套不同网域的oracle数据库,之间的数据需要进行...