# JeecgBoot连接达梦数据库 #### 一、达梦数据库官网下载地址 [http://www.dameng.com/down.aspx?TypeId=11&FId=t14:11:14](http://www.dameng.com/down.aspx?TypeId=11&FId=t14:11:14) ``` 项目采用DMB8开发版(windows64位) ``` #### 二、需要DmJdbcDriver18jar,可在达梦数据库安装路径下找到(maven仓库没有) ``` 1.达梦数据库驱动 DmJdbcDriver18.jar 路径:/dirvers/jdbc ``` #### 三、jeecg-boot 后台配置 1. 示例将jar放在src下的lib中 ![](https://img.kancloud.cn/b4/c9/b4c9d47010800651419a0f66283f0c02_364x126.png) 2. 后台system中的pom文件新增jar包引入 ``` <!-- 达梦驱动包--> <dependency> <groupId>com.dm</groupId> <artifactId>DmJdbcDriver18</artifactId> <version>1.8</version> <scope>system</scope> <systemPath>${project.basedir}/src/lib/DmJdbcDriver18.jar</systemPath> </dependency> <!-- c3p0数据库连接池--> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> ``` 3. application.yml ``` 将 spring: dataSource: 下配置内容注释掉 ``` 4.resources下新增jdbc.properties ``` jdbc.url=jdbc:dm://localhost:5236/SYSDBA&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true jdbc.username=SYSDBA jdbc.password=SYSDBA jdbc.driverClass=dm.jdbc.driver.DmDriver cpool.checkoutTimeout=50000 cpool.minPoolSize=1 cpool.maxPoolSize=3 cpool.maxIdleTime=7200 cpool.maxIdleTimeExcessConnections=1800 cpool.acquireIncrement=2 ``` 5.resources下新增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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 自动扫描--> <context:component-scan base-package="org.jeecg"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 加载jdbc文件--> <context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/> <!-- 配置数据库 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driverClass}"/> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="checkoutTimeout" value="${cpool.checkoutTimeout}" /> <property name="minPoolSize" value="${cpool.minPoolSize}" /> <property name="maxPoolSize" value="${cpool.maxPoolSize}"/> <property name="maxIdleTime" value="${cpool.maxIdleTime}"/> <property name="maxIdleTimeExcessConnections" value="${cpool.maxIdleTimeExcessConnections}" /> <property name="acquireIncrement" value="${cpool.acquireIncrement}" /> </bean> <!-- 配置语言包,因达activiti不支持达梦数据库,因达梦数据库仿照Oracle数据库,故用oracle语言包--> <bean id="sessionFactory2" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.Oracle8iDialect </value> </property> </bean> <!-- 事务配置--> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="dataSource" ref="dataSource"/> <property name="sessionFactory" ref="sessionFactory2"/> </bean> <!-- activiti配置--> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="dataSource" /> <property name="jobExecutorActivate" value="false" /> <!-- 如果数据库没有表时请将false改成true --> <property name="databaseSchemaUpdate" value="false"/> <property name="transactionManager" ref="transactionManager"/> <!-- 将类型设置为oracle--> <property name="databaseType" value="oracle"/> <property name="dbIdentityUsed" value="false" /> <property name="history" value="full" /> </bean> </beans> ``` 6.启动器(jeecgApplication)配置引入applicationContext.xml ``` @ImportResource("classpath:applicationContext.xml") ``` #### 四、达梦数据库可视化工具和数据库迁移工具 按win键找到达梦数据库,打开后可看见 ![](https://img.kancloud.cn/c1/4d/c14d74539066cace0a863097e8aca875_274x469.png) DM管理工具为可视化工具 数据库迁移可将mysql、orcale等数据库转换成达梦数据库 注意:当数据迁移时, ![](https://img.kancloud.cn/81/aa/81aac57d7251fee9d6103b8742b30ee7_273x270.png) 用户名称需和模式名称一致,否则sql语句需要模式名.表名才能访问数据库,不然会报错