暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OceanBase Cloud快速入门第27期:如何用 MyBatis 连接 OceanBase 数据库?

欢迎访问 OceanBase 官网获取更多信息:https://www.oceanbase.com/


配置依赖

<dependency>
   <groupId>com.oceanbase</groupId>
   <artifactId>oceanbase-client</artifactId>
   <version>2.4.0</version>
</dependency>
<dependency>
   <groupId>org.mybatis</groupId>
   <artifactId>mybatis</artifactId>
   <version>3.5.4</version>
</dependency>

配置文件

mybatis-config.xml 文件

内容如下:

<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.alipay.oceanbase.jdbc.Driver"/>
                <property name="url" value="jdbc:oceanbase://10.100.xxx.xxx:18817/test?useUnicode=true&amp;characterEncoding=utf-8&amp;useServerPrepStmts=false&amp;useCursorFetch=true"/>
                <property name="username" value="admin@mysql"/>
                <property name="password" value="admin"/>
            </dataSource>
        </environment>
    </environments>

    <!--注册mapper(mapper.xml所在地址)-->
    <mappers>
        <mapper resource="com/test/UserMapper.xml"></mapper>
    </mappers>
</configuration>

mapper.xml 文件

内容如下:

<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace 是mapper接口,不能填错-->
<mapper namespace="com.test.UserMapper">
    <select id="selectUser" resultType="com.test.User" fetchSize="40000">
        select * from user;
    </select>

    <delete id="delete" >
        delete from user;
    </delete>
</mapper>



欢迎访问 OceanBase 官网获取更多信息:https://www.oceanbase.com/

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论