首页 新闻 搜索 专区 学院

mybatis使用session.commit()提交不了

0
[已解决问题] 解决于 2016-07-15 14:37

<?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:@//localhost:1521/orcl" />
<property name="username" value="sa" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/DistrictMapper.xml" />
</mappers>
</configuration>

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.DistrictDao">
<select id="select" resultType="entity.District">
select * from District
</select>

<select id="selectById" parameterType="int" resultType="entity.District">
select *
from District where id = #{id}
</select>

<select id="add">
INSERT INTO District (id,name)
VALUES (#{0},#{1})
</select>

<select id="del" parameterType="int">
delete District where id = #{id}
</select>
</mapper>

 

 

public class TestSession {
public static void main(String[] args) {
try {
InputStream config=Resources.getResourceAsStream("mybatis.xml");
SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(config);
SqlSession session=factory.openSession();
DistrictDao dao=session.getMapper(DistrictDao.class);
dao.add(3001, "安徽1");
session.commit();
session.close();

} catch (IOException e) {
e.printStackTrace();
}

}
}

通过session.commit(true)是可以提交的

木哆哆哆的主页 木哆哆哆 | 菜鸟二级 | 园豆:204
提问于:2016-06-30 13:56
< >
分享
最佳答案
0

<select id="add">
INSERT INTO District (id,name)
VALUES (#{0},#{1})
</select>

这些插入的标签该用<insert id="add">INSERT INTO ...</insert>吧?

奖励园豆:5
加洲旅馆2012 | 小虾三级 |园豆:503 | 2016-07-07 09:01
其他回答(1)
0

commit前没有 update/insert/delete操作?

彩虹栗子 | 园豆:202 (菜鸟二级) | 2016-06-30 16:42

不是有增加吗

支持(0) 反对(0) 木哆哆哆 | 园豆:204 (菜鸟二级) | 2016-06-30 20:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册