Mybatis如何得到sqlSession,即数据库的连接
来源:互联网 发布:美工连捅策划7刀新闻 编辑:程序博客网 时间:2024/06/17 02:16
(1)sqlSession的作用
1、向SQL语句传入参数;
2、执行SQL语句;
3、获取执行SQL语句的结果;
4、事务的控制。
(2)如何得到sqlSession:
1、通过配置文件获取数据库连接信息;
2、通过配置信息构建SqlSessionFactory;
3、通过SqlSessionFactory打开数据库会话。
例:
public SqlSession getSqlSession() throws IOException{
//通过配置文件获取数据库连接信息,传入配置文件的包路径
Reader reader=resources.getResourceAsReader("com/config/configuration.xml");
//通过配置信息构建SqlSessionFactory
SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);
//通过SqlSessionFactory打开一个数据库会话
SqlSession
SqlSession sqlSession =sqlSessionfacory.openSession();
//返回sqlSession对象
return sqlSession;
}
0 0
- Mybatis如何得到sqlSession,即数据库的连接
- 浅谈Sqlsession和数据库的连接池
- mybatis的Sqlsession问题
- Mybatis的SqlSession
- myBatis获取SqlSession连接对象的两种方式
- Mybatis中如何获取SqlSession
- Mybatis中如何获取SqlSession
- 如何构建mybatis线程安全的sqlsession对象
- 单纯使用Mybatis框架 如何构建线程安全的SqlSession
- MyBatis的工具类SqlSession
- Mybatis SqlSession
- mybatis sqlsession
- MyBatis sqlSession
- SqlSessionFactory创建SqlSession测试mybatis的sql
- 关于MyBatis sqlSession的一点整理
- 关于MyBatis sqlSession的一点整理
- mybatis non transactional SqlSession的解决
- Mybatis-Spring 的高级配置(SqlSession)
- ZooKeeper原理及使用
- 懂商业的技术合伙人(13):谈谈我对商业的4点理解,创业公司做好核心业务是关键
- 关于制作图桌互联网订桌系统的思考
- yolo训练自己的数据
- Java 中的集合框架
- Mybatis如何得到sqlSession,即数据库的连接
- USACO
- [python]偶遇奇技淫巧-20170514
- liunx实战应用~redis安装
- 读书笔记《Effective C++》条款19:设计class犹如设计type
- C++作业六
- 计算两个日期的间隔天数(难度:1颗星)
- Valid Parentheses
- 2017.5.14