版权声明:[ws - 兮的博客] - 空间专属,未经声明不得私自转载 https://blog.csdn.net/qq_41463655/article/details/84182927
上一篇文章搭建了 ssm 框架,使用的是mysql
接下来连接 oracle,
更改逆向工程配置
jar 驱动包下载链接:https://pan.baidu.com/s/1AXP8f3OhtMNT3V63_bkryQ 密码:i9md
<!-- 制定mybatis 的驱动包的路径 千万别放中文路径下 -->
<classPathEntry location="D:\java\ep\mysql-connector-java-5.0.8-bin.jar" />
改为
<!-- 制定oracle 的驱动包的路径 千万别放中文路径下-->
<classPathEntry location="D:\java\ep\ojdbc14-10.2.0.2.0.jar" />
在更改
<!-- mysql -->
<!--
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/ssm_demo?characterEncoding=utf-8" userId="root" password="sweet"/>
-->
改为
<!-- oracle -->
<jdbcConnection driverClass="oracle.jdbc.OracleDriver" connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl" userId="sweet2" password="sweet2" />
运行,生成了oracel 逆向工程文件,oracle 数据库表间自行创建了
更改 jdbc 配置文件
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.url=jdbc:mysql://localhost:3306/ssm_demo?autoReconnect=true&useUnicode=true&characterEncoding=utf8
#jdbc.username=root
#jdbc.password=sweet
#最大连接数
c3p0.maxPoolSize=30
#最小连接数
c3p0.minPoolSize=10
#关闭连接后不自动commit
c3p0.autoCommitOnClose=false
#获取连接超时时间
c3p0.checkoutTimeout=10000
#当获取连接失败重试次数
c3p0.acquireRetryAttempts=2
#连接oracle数据库
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
jdbc.username=sweet2
jdbc.password=sweet2
添加oracle 连接的jar 依赖(不能使用maven,无授权),这里我 6 和14 版本都引入了
jar下载链接:https://pan.baidu.com/s/1HB_CKa_XlWpdbkCoVmivEg 密码:gtir
添加库,确定选择 jar 开头的
如下多了 箭头就引入成功了
在这里插入代码片
创建 mapper 接口类
public interface EbItemMapper {
public EbItem selectByPrimaryKey(Integer id);
//查询所有
public List<EbItem> selectAll();
}
mapper.xml 添加查询所有 ,要求 id 和 dao 层方法名一致
<select id="selectAll" resultMap="BaseResultMap">
select * from EB_ITEM
</select>
测试类测试
类上注解别忘了
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({“classpath:spring-mybatis.xml”})
@Autowired
private EbItemMapper ebItemMapper;
//id查询
@org.junit.Test
public void selectItemId(){
EbItem ebItem = ebItemMapper.selectByPrimaryKey(1);
System.out.println(ebItem.toString());
}
//查询所有
@org.junit.Test
public void selectItemId(){
List<EbItem> ebItems = ebItemMapper.selectAll();
for (EbItem ebItem : ebItems){
System.out.println(ebItem.toString());
}
}
获得数据