Java 当提示更新时,数据库表不会更新

Java 当提示更新时,数据库表不会更新,java,jdbc,Java,Jdbc,这是我想问的另一个问题,关于我在上一个问题中问过的“卡坦定居者”数据库。这次是关于更新数据库表本身 我成功地将Java应用程序连接到Oracle数据库,当应用程序提示更新其他数据库表时,其他数据库表也成功更新,但由于某些原因,这个数据库表尤其没有更新。它也没有错误,所以我排除了可能是连接或SQL命令问题 以下是我要更新的表: CREATE TABLE giocatore( numero INT, colore VARCHAR2(20), punto_partenza IN

这是我想问的另一个问题,关于我在上一个问题中问过的“卡坦定居者”数据库。这次是关于更新数据库表本身

我成功地将Java应用程序连接到Oracle数据库,当应用程序提示更新其他数据库表时,其他数据库表也成功更新,但由于某些原因,这个数据库表尤其没有更新。它也没有错误,所以我排除了可能是连接或SQL命令问题

以下是我要更新的表:

CREATE TABLE giocatore(
    numero INT,
    colore VARCHAR2(20),
    punto_partenza INT,
    punti_vittoria INT DEFAULT 0,
    vittorioso CHAR(1) DEFAULT 'f',
    quant_clay INT,
    quant_wool INT,
    quant_wheat INT,
    quant_wood INT,
    quant_rock INT,
    CONSTRAINT player_pk PRIMARY KEY(numero)
    );
下面是讨论中的Java应用程序代码:

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
        try{
            String url="jdbc:oracle:thin:@//localhost:1521/orcl";
            OracleDataSource ods = new OracleDataSource();
            ods.setURL(url);
            ods.setUser("LAB_NICK");
            ods.setPassword("10Niroxxe98");
            Connection conn = ods.getConnection();
            String PlayerNumberAsString = playerNum.getSelectedItem().toString();
            int PlayerNumber = Integer.parseInt(PlayerNumberAsString);
            String StartingHexagonNumberAsString = startHex.getSelectedItem().toString();
            int StartingHexagonNumber = Integer.parseInt(StartingHexagonNumberAsString);
            int VictoryPoints = (int) victoryPts.getValue();
            int OwnedAmountOfClay = (int) clayNum.getValue();
            int OwnedAmountOfWood = (int) woodNum.getValue();
            int OwnedAmountOfMinerals = (int) rockNum.getValue();
            int OwnedAmountOfWheat = (int) wheatNum.getValue();
            int OwnedAmountOfWool = (int) woolNum.getValue();
            String PlayerColor = colorChoice.getSelectedItem().toString();
            String IsVictorious;
            if(victoryCheck.isSelected()){
                IsVictorious = "v";
            }else{
                IsVictorious = "f";
            }
            PreparedStatement stmt = conn.prepareStatement("UPDATE giocatore SET punti_vittoria = ?, colore = ?, vittorioso = ?, punto_partenza = ?, quant_clay = ?, quant_wool = ?, quant_wheat = ?, quant_wood = ?, quant_rock = ? WHERE numero = ?");
            stmt.setInt(1, VictoryPoints);
            stmt.setString(2, PlayerColor);
            stmt.setString(3, IsVictorious);
            stmt.setInt(4, StartingHexagonNumber);
            stmt.setInt(5, OwnedAmountOfClay);
            stmt.setInt(6, OwnedAmountOfWool);
            stmt.setInt(7, OwnedAmountOfWheat);
            stmt.setInt(8, OwnedAmountOfWood);
            stmt.setInt(9, OwnedAmountOfMinerals);
            stmt.setInt(10, PlayerNumber);
            stmt.close();
            conn.close();
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }
我也想知道如何刷新JTable,但这是另一个时间的问题。谢谢你的理解


编辑:我之前发布的代码完全正常工作。这是我真正想问的代码。对于给您带来的不便,我深表歉意。

该代码中没有提交操作,因此,如果您的数据库未处于自动提交模式,您的事务将在完成时自动回滚。你能确认你的数据库是否处于自动提交模式吗?@JonK autocommit模式被激活。啊,更新的代码片段很好地显示了实际问题-你已经设置好了准备好的语句,然后。。。没有执行就关闭了它!现在明白了,我犯了一个多么愚蠢的错误。谢谢如果发生在我们中最好的人身上,那么代码中不会发生提交,因此如果您的数据库未处于自动提交模式,那么您的事务将在完成时自动回滚。你能确认你的数据库是否处于自动提交模式吗?@JonK autocommit模式被激活。啊,更新的代码片段很好地显示了实际问题-你已经设置好了准备好的语句,然后。。。没有执行就关闭了它!现在明白了,我犯了一个多么愚蠢的错误。谢谢发生在我们最好的人身上,不客气