如何在会话一中重用executeQuery

时间:2019-06-21 02:36:51

标签: java sql-server

我用黄瓜做BDD:

第1步:运行excecuteQuery->在数据库中正确显示值第3列(示例:1.000)

第2步:将API加上金额添加到数据库中(例如:2.000)

第3步:Re-excecuteQuery =>值显示不正确(预期为:3.000)

public int variableTotalAmount() { 
    MysqlConnect mysqlConnect = new MysqlConnect(); 
    int amountVariable = 0; 
    String sql = "sql"; 
    try { 
        Statement stmt = mysqlConnect.connect().createStatement(); 
        ResultSet rs = stmt.executeQuery(sql); 
        while (rs.next()) { 
            amountVariable = rs.getInt(3); 
        } 
    } 
    catch (SQLException e) { 
        e.printStackTrace(); 
    } 
    finally {
        mysqlConnect.disconnect(); 
    } 
    return amountVariable; 
} 

0 个答案:

没有答案