lxf1maple 2010-03-16 22:51
浏览 267
已采纳

ibatis插入失败

大家好,我碰到了一个诡异的问题,都不知道怎么黏贴我的代码。具体情况是这样的:

我通过页面录入信息,向数据库插入数据,结果插入数据有的时候能够插入有的时候程序也不报错,跟踪调试进入运行正常,但是就是数据库中没有记录,放着不管他,过一会再从页面操作一下,结果又能插入记录了,然后再操作几次又不能插入了,简直太诡异了 。

web环境是 持久层用ibatis ,数据库mysql。 哪位能有些建议啊,郁闷死了。

dao层代码:
public void insertKulapati(Person person,Kulapati kul) throws SQLException{
try{
DBUtil.startTransaction();
int id = (Integer)DBUtil.insertObject(insertPerson,person);
kul.setPid(id );
DBUtil.insertObject(insertKulapati, kul);
DBUtil.commitTransaction();
}catch(SQLException ex){
ex.printStackTrace();
try {
DBUtil.endTransaction();
} catch (SQLException e) {

        }
        throw ex;
    }
}

DBUtil相关代码:

初始化:
/**
* SqlMapClient instances are thread safe, so you only need one. In this
* case, we'll use a static singleton. So sue me. ;-)
*/
private static SqlMapClient sqlMapper;

/**
 * It's not a good idea to put code that can fail in a class initializer,
 * but for sake of argument, here's how you configure an SQL Map.
 */
static {
    try {
        Reader reader = Resources
                .getResourceAsReader("config/SqlMapConfig.xml");
        sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(
                "Something bad happened while building the SqlMapClient instance."
                        + e, e);
    }
}

事物控制:
public static void startTransaction() throws SQLException {
sqlMapper.startTransaction();
}
/**
* 提交事物
* @throws SQLException
/
public static void commitTransaction() throws SQLException {
sqlMapper.commitTransaction();
}
/
*
* 关闭事物,回滚
* @throws SQLException
*/
public static void endTransaction() throws SQLException{
sqlMapper.endTransaction();
}

然后插入操作就是调用sqlclient很简单的。多谢各位了。

补充一下: 每次将tomcat重启之后,就可以插入几个记录,然后就再也插入不成功了,但是程序不报错,调试跟踪主键也一直递增。

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Win7电脑开机出现硬件设置已更改
      • ¥15 vba代出现莫须有错误,都是一个个复制下来的为啥出错呢?
      • ¥15 /etc/vsftpd/vsftp.conf配置文件加了一行utf8_filesystem=YES之后,启动vsftpd报错
      • ¥15 W5100可以收广播,但是无法发出广播
      • ¥100 PCD点云排序和分割
      • ¥15 GG-CNN抓取数据集
      • ¥15 C++类和对象,多态性,继承,虚函数虚基类
      • ¥15 使用VS2019和Dev c++按%p输出地址,结果相差很大
      • ¥30 有偿解惑TINA老报错,求解惑
      • ¥15 arduino esp8266 编译问题