ssh2 配置 连接数据库

来源:互联网 发布:图片放大缩小js插件 编辑:程序博客网 时间:2024/04/28 02:54

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/TrdMS
jdbc.username=root
jdbc.password=root

<!--org.hibernate.dialect.MySQLDialect-->

hibernate.show_sql=true
hibernate.hbm2ddl.auto=update


#oracle
#hibernate.dialect=org.hibernate.dialect.OracleDialect
#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
#jdbc.url=jdbc:oracle:thin:@xx.xx.xx.xx:1521:easyssh
#jdbc.username=test
#jdbc.password=test


#mysql-company
#hibernate.dialect=org.hibernate.dialect.MySQLDialect
#jdbc.driverClassName=com.mysql.jdbc.Driver
#jdbc.url=jdbc\:mysql\://192.168.0.133\:3306/bang
#jdbc.username=root
#jdbc.password=root



#sqlserver
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
#jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
#jdbc.url=jdbc\:sqlserver\://xxxxxxxxxxxxxx\:1433;databaseName\=bang
#jdbc.username=sa
#jdbc.password=xxxx123456


<?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-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
         http://www.springframework.org/schema/aop
         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.favorlove" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>


<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:email.properties</value>
</list>
</property>
</bean>


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${jdbc.url}
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.TrdMS.model</value>
</list>
</property>
</bean>


<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>


<aop:config>
<aop:pointcut expression="execution(public * com.TrdMS.service..*.*(..))"
id="productServiceMethods" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>

</beans> 


////////////////////////////////////////////////////////////////////////////////////////////////////SQL

<!--  定义数据源   -->
<bean id="sqlserver"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://localhost:1591;databaseName=project">
</property>
<property name="username" value="sa"></property>
<property name="password" value="123456"></property>
</bean>

<!--  定义Hibernate的sessionFactory --> 
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--  指定数据源   --> 
<property name="dataSource">
<ref bean="sqlserver" />
</property>

<property name="hibernateProperties">
<props>
<!--  指定使用方言   -->
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>