我正在尝试使用 MyBatis 将小型 Java 应用程序与数据库连接起来。
XML 文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!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="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@xxxx:xxxx:xxxx"/>
<property name="username" value="xxxxx"/>
<property name="password" value="xxxxx"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="xml/Mapper.xml"/>
</mappers>
</configuration>
之前,我得到的会话如下
String resource = "Configuration.xml";
SqlSession session = null;
try{
Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
session = sqlMapper.openSession();
我想在不使用 xml 文件的情况下连接到数据库。任何帮助将不胜感激。