Sqlite数据库不使用java更新

时间:2015-12-14 11:44:47

标签: java sqlite

我正在尝试更新我的新数据库,但出于某种原因,在执行我的Prepared Statement之后数据保持不变。它不返回任何错误或任何异常。请查看我的代码,看看你是否可以帮助我。提前谢谢。

    try {
connect();
PreparedStatement update = con.prepareStatement("UPDATE generalInfo SET "
+ "site" + " = '"
+ siteTt + "' , "
+ "area" + " = '"
+ areaTt + "' , "
+ "unit" + " = '"
+ unitTt + "' , "
+ "unitName" + " = '"
+ unitNameTt + "' , "
+ "drawing" + " = '"
+ drawingTt + "' , "
+ "system" + " = '"
+ systemTt + "' , "
+ "stream" + " = '"
+ streamTt + "' , "
+ "product" + " = '"
+ productTt + "' , "
+ "equipmentLoc" + " = '"
+ equipLocTt + "' , "
+ "specificLoc" + " = '"
+ specificLocTt + "' , "
+ "camOperator" + " = '"
+ camTechTt + "' , "
+ "camSerial" + " = '"
+ camSerialTt + "' , "
+ "gasSurveyOperator" + " = '"
+ surveyTechTt + "' , "
+ "gasSurveySerial" + " = '"
+ surveySerialTt + "' , "
+ "equipmentDesc" + " = '"
+ equipDescTt + "' , "
+ "equipmentType" + " = '"
+ equipTypeTt + "' , "
+ "equipmentSize" + " = '"
+ equipSizeTt + "' , "
+ "equipmentID" + " = '"
+ equipIDTt + "' , "
+ "[Maintenance type]" + " = '"
+ repairTt + "' , "
+ "measurementPosition" + " = '"
+ sourceTt + "'"                  
+ " WHERE leakerID = " + Integer.parseInt(leakerIDCombo.getSelectedItem().toString())+";");
update.closeOnCompletion();
update.executeUpdate();
con.close();
System.out.println("saved");
    } catch (SQLException ex) {
        Logger.getLogger(RefineryData.class.getName()).log(Level.SEVERE, null, ex);
    }

1 个答案:

答案 0 :(得分:1)

永远不会忘记commit您的更改:

con.setAutoCommit(true);
update.closeOnCompletion();
update.executeUpdate();
con.close();

update.closeOnCompletion();
update.executeUpdate();
con.commit();
con.close();