java - 提示时数据库表不更新
问题描述
这是我一直想问的另一个问题,关于我在上一个问题中问过的同一个“卡坦定居者”数据库。这一次是关于更新数据库表本身。
我成功地将 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,但这是另一个问题。感谢您的理解。
编辑:我之前发布的代码完全可以工作。这是我实际询问的代码。对于给您带来的重大不便,我深表歉意。
解决方案
推荐阅读
- laravel - Laravel 多次检索已删除的用户
- windows - 如何在 Windows 10 上显示 Android Studio IDE 颜色
- python - Tensorflow GRU 层调用()参数——TypeError:调用()得到了一个意外的关键字参数“reset_after”
- c - 无法保存从 ESP32Cam 模块拍摄的正确 jpg 格式图片,并且无法在 Windows 中打开
- java - 无法找到请求目标的有效证书路径 (SSLHandshakeException)
- entity-framework-core - 使用 FORMAT 命令转换 SQL 查询以在实体框架核心中使用
- python - 如何使用 Python 从相机 (Nikon D5600) 读取图像文件
- maven - 无法解析 gmaven 插件中的类 util
- python - 如何使用python从子目录下的文件名中删除多个字符?
- elasticsearch - 在聚合中添加脚本 - 弹性搜索