0

我遇到了一个奇怪的问题:我对 MySQL 5.1 数据库进行了 SELECT 查询,提交了 UPDATE 查询,之后无法再次进行 SELECT 查询(Java 抱怨找不到该列)。

这是我的代码:
//SELECT

 dbhIrmdb.setAutoCommit(false);
 PreparedStatement preparedSelect=null;
        preparedSelect=dbhIrmdb.prepareStatement(query);
        ResultSet rowSet=preparedSelect.executeQuery();
        dbhIrmdb.commit();
        while (rowSet.next()) {
            computer=new ComputerInfo();
            computer.setIndex(index); index++;
            computer.setComputers_id(rowSet.getString("computers_id"));
            ....
        }
 dbhIrmdb.setAutoCommit(true);

//更新

 PreparedStatement commonUpdate=null;
    try {
        String queryUpdate="UPDATE computers SET name=?, serial=?, inv_number=?, comments=?, rack_unit=?, box_unit=?, ram=? WHERE ID="
                +currentComp.getComputers_id();
        dbhIrmdb.setAutoCommit(false);
        commonUpdate=dbhIrmdb.prepareStatement(queryUpdate);
        commonUpdate.setString(1, currentComp.getComputers_name());
        ...
        commonUpdate.executeUpdate();
        dbhIrmdb.commit();
    } catch (SQLException ex) {
        ex.printStackTrace();
        try {
            System.err.print("Transaction is being rolled back");
            dbhIrmdb.rollback();
        } catch(SQLException excep) {
            excep.printStackTrace();
        } 
    } 
    finally {
        if (commonUpdate != null) {
            commonUpdate.close();
        }
        dbhIrmdb.setAutoCommit(true);
    }

我通过该网站进行了深入研究,但找不到这样的案例。

我将不胜感激任何帮助或建议。

4

1 回答 1

0

你已经computers_id进去//SELECT blockID//UPDATE

在 //UPDATE 块中试试这个

String queryUpdate="UPDATE computers SET name=?, serial=?, inv_number=?, comments=?, rack_unit=?, box_unit=?, ram=? WHERE computers_id="
            +currentComp.getComputers_id();
于 2013-09-06T07:51:58.130 回答