为什么我的JDBC准备语句更新不更新数据库? [英] Why is my JDBC prepared statement update not updating the database?

查看:108
本文介绍了为什么我的JDBC准备语句更新不更新数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDBC更新MySQL数据库中的一行:

I am using JDBC to update a row in my MySQL database:

    pConnection.setAutoCommit(true); 

    PreparedStatement pstmt = pConnection.prepareStatement("update mg_build_queue " + //
            "set buildsetid=?,locale=?,areacode=?,distversionid=?,platformid=?,version=?," + //
            "priority=?,buildstatus=?,computername=?,buildoutput=?,started=?,finished=?, packageid=?, lockcounter=0 where buildid=?" //
    );

    pstmt.setInt(1, mBuildSet.getId());
    pstmt.setString(2, Locale.localesToString(mLocales, ","));
    pstmt.setString(3, mAreaCode.toString());
    pstmt.setInt(4, mDistVersionId);
    pstmt.setInt(5, mPlatform);
    pstmt.setInt(6, mVersion);
    pstmt.setLong(7, mPriority);
    pstmt.setInt(8, mBuildStatus);
    pstmt.setString(9, mComputerName);
    pstmt.setString(10, mBuildOutput);
    pstmt.setTimestamp(11, timeToTimestamp(mStarted));
    pstmt.setTimestamp(12, timeToTimestamp(mFinished));
    pstmt.setInt(13, mResultPackageId);
    pstmt.setInt(14, mBuildId);

    LOGGER.debug("Updating data for mg_build_queue: " + pstmt);
    pstmt.execute();
    LOGGER.debug("Updated " + pstmt.getUpdateCount() + " rows."); 

这将产生以下输出:

2012-05-24 09:54:33,211 [Thread-1] DEBUG com.buildmaster.BuildQueueEntryImpl - Updating data for mg_build_queue: com.mysql.jdbc.JDBC4PreparedStatement@35e09eab: update mg_build_queue set buildsetid=201,locale='FR',areacode='XX',distversionid=95,platformid=4604,version=65807,priority=33652480,buildstatus=1,computername='MY_COMPUTER-C:\\BUILDS',buildoutput='',started='2012-05-24 09:54:33',finished='2012-05-24 19:45:27', packageid=0, lockcounter=0 where buildid=122418
2012-05-24 09:54:33,214 [Thread-1] DEBUG com.buildmaster.BuildQueueEntryImpl - Updated 1 rows.

我也没有例外.如果在DBVisualizer中查询条目,则只会看到旧值.如果在DBVisualizer中手动运行命令(从上面复制并粘贴),则可以看到更新后的值.

I see no exception. If I query for the entry in DBVisualizer, I see only the old value. If I run the command by hand in DBVisualizer (copied and pasted from above), I can see the updated value.

为什么会这样?

推荐答案

问题似乎是DBVisualizer正在执行某些结果缓存.我已断开连接并使用DBVisualizer重新连接,并且可以看到更新.感谢所有人的建议.

The issue appears to be that DBVisualizer is doing some result caching. I disconnected and reconnected using DBVisualizer and can see the update. Thanks to all for their suggestions.

感谢DBVisualizer论坛上的 Hans Bergsten ,这里是如何预防我的问题:

Thanks to a Hans Bergsten on the DBVisualizer forums, here is how to prevent my issue:

工具->工具属性->数据库-> MySQL->物理连接

Tools -> Tool Properties -> Database -> MySQL -> Physical Connection

Transaction Isolation更改为TRANSACTION_READ_COMMITTED.

注意,我还重新启动了MySQL数据库,我认为该数据库不受影响,但是值得一提.

NOTE I also restarted my MySQL database, which I don't think affected things, but is worth mentioning.

这篇关于为什么我的JDBC准备语句更新不更新数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆