Mybatis 中获得 connection
Posted libin6505
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis 中获得 connection相关的知识,希望对你有一定的参考价值。
转:
Mybatis 中获得 connection
-
-
private SqlSession sqlSession;
-
public Connection getConnection(){
-
Connection conn = null;
-
try {
-
conn = sqlSession.getConfiguration().getEnvironment().getDataSource().getConnection();
-
logger.info("===This Connection isClosed ? "+conn.isClosed());
-
} catch (Exception e) {
-
e.printStackTrace();
-
}
-
return conn;
-
}
-
String resource = "SqlMap.xml"; Reader reader = Resources.getResourceAsReader(resource);
-
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
-
Connection db = sqlMap.getDataSource().getConnection();
-
Statement st = db.createStatement();
-
ResultSet rs = st.executeQuery("show tables");
以上是关于Mybatis 中获得 connection的主要内容,如果未能解决你的问题,请参考以下文章