奇怪的 SQLite 行为 - 非功能性 UPDATE SQLite 方法
Weird SQLite behaviour - non-functional UPDATE SQLite method
我正在创建一个 Java 桌面应用程序,该应用程序使用具有 50 多个数据变量的 SQLite 数据库。我有一个具有以下变量的 DatabaseHelper class:
//-- The SQLite Database Table name --//
private static final String STAN_RECORDS_TABLE = "STAN_SQLite_Records_Table"; // Primary Table - Table 1.
//-- The STAN Records DATABASE TABLE COLUMNS - or KEYS - defined here as static variables. --//
private static final String STAN_KEY_RECORDS_ID = "Stan_Records_id"; // Record 1
private static final String STAN_KEY_DATE_CREATED = "Date_Created"; // Record 2
private static final String STAN_KEY_EST_TYPE = "Stan_Est_Type"; // Record 3
private static final String STAN_KEY_CITY_TOWN = "City_Town"; // Record 4
private static final String STAN_KEY_LOC_LAT = "Loc_Lat"; // Record 5
private static final String STAN_KEY_LOC_LONG = "Loc_Long"; // Record 6
private static final String STAN_KEY_STREET_NAME = "Street_Name"; // Record 7
private static final String STAN_KEY_ERF_NUM = "Erf_Number"; // Record 8
private static final String STAN_KEY_SUBURB_NAME = "Suburb_Name"; // Record 9
private static final String STAN_KEY_ADDRESS_DESC = "Address_Desc"; // Record 10
private static final String STAN_KEY_RATE_SINGLE = "Single_Rate"; // Record 11
private static final String STAN_KEY_RATE_DOUBLE = "Double_Rate"; // Record 12
private static final String STAN_KEY_RATE_FAMILY = "Family_Rate"; // Record 13
private static final String STAN_KEY_RATE_VIP = "VIP_Rate"; // Record 14
private static final String STAN_KEY_CONTACTS_FIXED = "Fixed_Line"; // Record 15
private static final String STAN_KEY_CONTACTS_FAX = "Facsimile"; // Record 16
private static final String STAN_KEY_CONTACTS_MOBILE = "Mobile"; // Record 17
private static final String STAN_KEY_CONTACTS_EMAIL = "Email"; // Record 18
private static final String STAN_KEY_CONTACTS_WEB = "Website"; // Record 19
private static final String STAN_KEY_SELF_CATER = "Self_Cater"; // Record 20
private static final String STAN_KEY_PARKING_TYPE = "Parking_Type"; // Record 21
private static final String STAN_KEY_PARKING_SHADE = "Parking_Shade"; // Record 22
private static final String STAN_KEY_PARKING_BAYS = "Parking_Bays"; // Record 23
private static final String STAN_KEY_PARKING_RATING = "Parking_Rating"; // Record 24
private static final String STAN_KEY_SINGLE_UNITS = "Single_Units"; // Record 25
private static final String STAN_KEY_SINGLE_DESC = "Single_Desc"; // Record 26
private static final String STAN_KEY_DOUBLE_UNITS = "Double_Units"; // Record 27
private static final String STAN_KEY_DOUBLE_DESC = "Double_Desc"; // Record 28
private static final String STAN_KEY_FAMILY_UNITS = "Family_Units"; // Record 29
private static final String STAN_KEY_FAMILY_DESC = "Family_Desc"; // Record 30
private static final String STAN_KEY_VIP_UNITS = "VIP_Units"; // Record 31
private static final String STAN_KEY_VIP_DESC = "VIP_Desc"; // Record 32
private static final String STAN_KEY_SINGLE_DOUBLE = "Single_Doubles"; // Record 33
private static final String STAN_KEY_ROOM_COND = "Room_Condition"; // Record 34
private static final String STAN_KEY_ROOM_PRIVACY = "Room_Privacy"; // Record 35
private static final String STAN_KEY_BATHROOM_SHARED = "Bathroom_Shared"; // Record 36
private static final String STAN_KEY_AIR_CON = "Air_Con"; // Record 37
private static final String STAN_KEY_ROOM_FRIDGE = "Room_Fridge"; // Record 38
private static final String STAN_KEY_ROOM_TV = "Room_TV"; // Record 39
private static final String STAN_KEY_ROOM_BEDDING = "Room_Bedding"; // Record 40
private static final String STAN_KEY_ROOM_SIZE = "Room_Size"; // Record 41
private static final String STAN_KEY_BONUS_POOL = "Bonus_Pool"; // Record 42
private static final String STAN_KEY_BONUS_GYM = "Bonus_Gym"; // Record 43
private static final String STAN_KEY_BONUS_BAR = "Bonus_Bar"; // Record 44
private static final String STAN_KEY_HOOD_NAME = "Hood_Name"; // Record 45
private static final String STAN_KEY_HOOD_SAFETY = "Hood_Safety"; // Record 47
private static final String STAN_KEY_HOOD_CBD = "Hood_CBD"; // Record 48
private static final String STAN_KEY_HOOD_NEARBY = "Hood_Nearby"; // Record 49
private static final String STAN_KEY_TOURIST_RECO = "Tourist_Reco"; // Record 50
private static final String STAN_KEY_TOURIST_REASON = "Tourist_Reason"; // Record 51
private static final String STAN_KEY_INFO_CANCEL_POLICY = "Cancel_Policy"; // Record 52
private static final String STAN_KEY_INFO_OTHER_INFO = "Other_Info"; // Record 53
private static final String STAN_KEY_EST_DB_SCORE = "Est_DB_Score"; // Record 54
private static final String STAN_KEY_DATE_UPDATED = "Date_Updated"; // Record 55
private static final String STAN_KEY_SHUTTLE_SERVICE = "Shuttle_Service"; // Record 55
private static final String STAN_KEY_KITCHEN_AVAILABLE = "Kitchen"; // Record 56
private static final String STAN_KEY_BREAKFASTS = "Breakfast"; // Record 57
private static final String STAN_KEY_FREE_WIFI = "Free_Wifi"; // Record 58
private static final String STAN_KEY_EST_NAME = "Est_Name"; // Record 59
然后我有一个数据库创建字符串:
//-- STAN Records TABLE creation SQL Statement --//
private static final String CREATE_STAN_RECORDS_TABLE = "CREATE TABLE IF NOT EXISTS " + STAN_RECORDS_TABLE + " (" + /*0*/ STAN_KEY_RECORDS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ /*1*/ STAN_KEY_EST_NAME + " VARCHAR(255)," + /*2*/ STAN_KEY_EST_TYPE + " VARCHAR(255), " + /*3*/ STAN_KEY_CITY_TOWN + " VARCHAR(255), " + /*4*/ STAN_KEY_DATE_CREATED + " VARCHAR(255), "
+ /*5*/ STAN_KEY_LOC_LAT + " VARCHAR(255), " + /*6*/ STAN_KEY_LOC_LONG + " VARCHAR(255), " + /*7*/ STAN_KEY_STREET_NAME + " VARCHAR(255), "
+ /*8*/ STAN_KEY_ERF_NUM + " VARCHAR(255), " + /*9*/ STAN_KEY_SUBURB_NAME + " VARCHAR(255), " + /*10*/ STAN_KEY_ADDRESS_DESC + " VARCHAR(255), "
+ /*11*/ STAN_KEY_RATE_SINGLE + " VARCHAR(255), " + /*12*/ STAN_KEY_RATE_DOUBLE + " VARCHAR(255), " + /*13*/ STAN_KEY_RATE_FAMILY + " VARCHAR(255), "
+ /*14*/ STAN_KEY_RATE_VIP + " VARCHAR(255), " + /*15*/ STAN_KEY_CONTACTS_FIXED + " VARCHAR(255), " + /*16*/ STAN_KEY_CONTACTS_FAX + " VARCHAR(255), "
+ /*17*/ STAN_KEY_CONTACTS_MOBILE + " VARCHAR(255), " + /*18*/ STAN_KEY_CONTACTS_EMAIL + " VARCHAR(255), " + /*19*/ STAN_KEY_CONTACTS_WEB + " VARCHAR(255), "
+ /*20*/ STAN_KEY_SELF_CATER + " VARCHAR(255), " + /*21*/ STAN_KEY_PARKING_TYPE + " VARCHAR(255), " + /*22*/ STAN_KEY_PARKING_SHADE + " VARCHAR(255), "
+ /*23*/ STAN_KEY_PARKING_BAYS + " VARCHAR(255), " + /*24*/ STAN_KEY_PARKING_RATING + " VARCHAR(255), " + /*25*/ STAN_KEY_SINGLE_UNITS + " VARCHAR(255), "
+ /*26*/ STAN_KEY_SINGLE_DESC + " VARCHAR(255), " + /*27*/ STAN_KEY_DOUBLE_UNITS + " VARCHAR(255), " + /*28*/ STAN_KEY_DOUBLE_DESC + " VARCHAR(255), "
+ /*29*/ STAN_KEY_FAMILY_UNITS + " VARCHAR(255), " + /*30*/ STAN_KEY_FAMILY_DESC + " VARCHAR(255), " + /*31*/ STAN_KEY_VIP_UNITS + " VARCHAR(255), "
+ /*32*/ STAN_KEY_VIP_DESC + " VARCHAR(255), " + /*33*/ STAN_KEY_SINGLE_DOUBLE + " VARCHAR(255), " + /*34*/ STAN_KEY_ROOM_COND + " VARCHAR(255), "
+ /*35*/ STAN_KEY_ROOM_PRIVACY + " VARCHAR(255), " + /*36*/ STAN_KEY_BATHROOM_SHARED + " VARCHAR(255), " + /*37*/ STAN_KEY_AIR_CON + " VARCHAR(255), "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + " VARCHAR(255), " + /*39*/ STAN_KEY_ROOM_TV + " VARCHAR(255), " + /*40*/ STAN_KEY_ROOM_BEDDING + " VARCHAR(255), "
+ /*41*/ STAN_KEY_ROOM_SIZE + " VARCHAR(255), " + /*42*/ STAN_KEY_BONUS_POOL + " VARCHAR(255), " + /*43*/ STAN_KEY_BONUS_GYM + " VARCHAR(255), "
+ /*44*/ STAN_KEY_BONUS_BAR + " VARCHAR(255), " + /*45*/ STAN_KEY_HOOD_NAME + " VARCHAR(255), " + /*46*/ STAN_KEY_HOOD_SAFETY + " VARCHAR(255), "
+ /*47*/ STAN_KEY_HOOD_CBD + " VARCHAR(255), " + /*48*/ STAN_KEY_HOOD_NEARBY + " VARCHAR(255), " + /*49*/ STAN_KEY_TOURIST_RECO + " VARCHAR(255), "
+ /*50*/ STAN_KEY_TOURIST_REASON + " VARCHAR(255), " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + " VARCHAR(255), " + /*52*/ STAN_KEY_INFO_OTHER_INFO+ " VARCHAR(255), "
+ /*53*/ STAN_KEY_EST_DB_SCORE + " INTEGER, " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + " VARCHAR(255), " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + " VARCHAR(255), "
+ /*56*/ STAN_KEY_BREAKFASTS + " VARCHAR(255), " + /*57*/ STAN_KEY_FREE_WIFI + " VARCHAR(255), " + /*58*/ STAN_KEY_DATE_UPDATED + " VARCHAR(255));";
...和记录插入字符串:
private static final String INSERT_ONE_COMPLETE_STAN_RECORDS_ENTRY = "INSERT INTO " + STAN_RECORDS_TABLE + " (" + /*1*/ STAN_KEY_EST_NAME + ", " + /*2*/ STAN_KEY_EST_TYPE + ", "
+ /*3*/ STAN_KEY_CITY_TOWN + ", " + /*4*/ STAN_KEY_DATE_CREATED + ", " + /*5*/ STAN_KEY_LOC_LAT + ", " + /*6*/ STAN_KEY_LOC_LONG + ", " + /*7*/ STAN_KEY_STREET_NAME + ", "
+ /*8*/ STAN_KEY_ERF_NUM + ", " + /*9*/ STAN_KEY_SUBURB_NAME + ", " + /*10*/ STAN_KEY_ADDRESS_DESC + ", " + /*11*/ STAN_KEY_RATE_SINGLE + ", " + /*12*/ STAN_KEY_RATE_DOUBLE + ", "
+ /*13*/ STAN_KEY_RATE_FAMILY + ", " + /*14*/ STAN_KEY_RATE_VIP + ", " + /*15*/ STAN_KEY_CONTACTS_FIXED + ", " + /*16*/ STAN_KEY_CONTACTS_FAX + ", " + /*17*/ STAN_KEY_CONTACTS_MOBILE + ", "
+ /*18*/ STAN_KEY_CONTACTS_EMAIL + ", " + /*19*/ STAN_KEY_CONTACTS_WEB + ", " + /*20*/ STAN_KEY_SELF_CATER + ", " + /*21*/ STAN_KEY_PARKING_TYPE + ", " + /*22*/ STAN_KEY_PARKING_SHADE + ", "
+ /*23*/ STAN_KEY_PARKING_BAYS + ", " + /*24*/ STAN_KEY_PARKING_RATING + ", " + /*25*/ STAN_KEY_SINGLE_UNITS + ", " + /*26*/ STAN_KEY_SINGLE_DESC + ", " + /*27*/ STAN_KEY_DOUBLE_UNITS + ", "
+ /*28*/ STAN_KEY_DOUBLE_DESC + ", " + /*29*/ STAN_KEY_FAMILY_UNITS + ", " + /*30*/ STAN_KEY_FAMILY_DESC + ", " + /*31*/ STAN_KEY_VIP_UNITS + ", " + /*32*/ STAN_KEY_VIP_DESC + ", "
+ /*33*/ STAN_KEY_SINGLE_DOUBLE + ", " + /*34*/ STAN_KEY_ROOM_COND + ", " + /*35*/ STAN_KEY_ROOM_PRIVACY + ", " + /*36*/ STAN_KEY_BATHROOM_SHARED + ", " + /*37*/ STAN_KEY_AIR_CON + ", "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + ", " + /*39*/ STAN_KEY_ROOM_TV + ", " + /*40*/ STAN_KEY_ROOM_BEDDING + ", " + /*41*/ STAN_KEY_ROOM_SIZE + ", " + /*42*/ STAN_KEY_BONUS_POOL + ", "
+ /*43*/ STAN_KEY_BONUS_GYM + ", " + /*44*/ STAN_KEY_BONUS_BAR + ", " + /*45*/ STAN_KEY_HOOD_NAME + ", " + /*46*/ STAN_KEY_HOOD_SAFETY + ", " + /*47*/ STAN_KEY_HOOD_CBD + ", "
+ /*48*/ STAN_KEY_HOOD_NEARBY + ", " + /*49*/ STAN_KEY_TOURIST_RECO + ", " + /*50*/ STAN_KEY_TOURIST_REASON + ", " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + ", "
+ /*52*/ STAN_KEY_INFO_OTHER_INFO+ ", " + /*53*/ STAN_KEY_EST_DB_SCORE+ ", " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + ", " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + ", "
+ /*56*/ STAN_KEY_BREAKFASTS + ", " + /*57*/ STAN_KEY_FREE_WIFI + ", " + /*58*/ STAN_KEY_DATE_UPDATED + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
...以及记录更新字符串(这是问题!!):
private static final String UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY = "UPDATE " + STAN_RECORDS_TABLE + " SET " + /*1*/ STAN_KEY_EST_NAME + " = ?, " + /*2*/ STAN_KEY_EST_TYPE + " = ?, "
+ /*3*/ STAN_KEY_CITY_TOWN + " = ?, " + /*4*/ STAN_KEY_DATE_CREATED + " = ?, " + /*5*/ STAN_KEY_LOC_LAT + " = ?, " + /*6*/ STAN_KEY_LOC_LONG + " = ?, " + /*7*/ STAN_KEY_STREET_NAME + " = ?, "
+ /*8*/ STAN_KEY_ERF_NUM + " = ?, " + /*9*/ STAN_KEY_SUBURB_NAME + " = ?, " + /*10*/ STAN_KEY_ADDRESS_DESC + " = ?, " + /*11*/ STAN_KEY_RATE_SINGLE + " = ?, " + /*12*/ STAN_KEY_RATE_DOUBLE + " = ?, "
+ /*13*/ STAN_KEY_RATE_FAMILY + " = ?, " + /*14*/ STAN_KEY_RATE_VIP + " = ?, " + /*15*/ STAN_KEY_CONTACTS_FIXED + " = ?, " + /*16*/ STAN_KEY_CONTACTS_FAX + " = ?, " + /*17*/ STAN_KEY_CONTACTS_MOBILE + " = ?, "
+ /*18*/ STAN_KEY_CONTACTS_EMAIL + " = ?, " + /*19*/ STAN_KEY_CONTACTS_WEB + " = ?, " + /*20*/ STAN_KEY_SELF_CATER + " = ?, " + /*21*/ STAN_KEY_PARKING_TYPE + " = ?, " + /*22*/ STAN_KEY_PARKING_SHADE + " = ?, "
+ /*23*/ STAN_KEY_PARKING_BAYS + " = ?, " + /*24*/ STAN_KEY_PARKING_RATING + " = ?, " + /*25*/ STAN_KEY_SINGLE_UNITS + " = ?, " + /*26*/ STAN_KEY_SINGLE_DESC + " = ?, " + /*27*/ STAN_KEY_DOUBLE_UNITS + " = ?, "
+ /*28*/ STAN_KEY_DOUBLE_DESC + " = ?, " + /*29*/ STAN_KEY_FAMILY_UNITS + " = ?, " + /*30*/ STAN_KEY_FAMILY_DESC + " = ?, " + /*31*/ STAN_KEY_VIP_UNITS + " = ?, " + /*32*/ STAN_KEY_VIP_DESC + " = ?, "
+ /*33*/ STAN_KEY_SINGLE_DOUBLE + " = ?, " + /*34*/ STAN_KEY_ROOM_COND + " = ?, " + /*35*/ STAN_KEY_ROOM_PRIVACY + " = ?, " + /*36*/ STAN_KEY_BATHROOM_SHARED + " = ?, " + /*37*/ STAN_KEY_AIR_CON + " = ?, "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + " = ?, " + /*39*/ STAN_KEY_ROOM_TV + " = ?, " + /*40*/ STAN_KEY_ROOM_BEDDING + " = ?, " + /*41*/ STAN_KEY_ROOM_SIZE + " = ?, " + /*42*/ STAN_KEY_BONUS_POOL + " = ?, "
+ /*43*/ STAN_KEY_BONUS_GYM + " = ?, " + /*44*/ STAN_KEY_BONUS_BAR + " = ?, " + /*45*/ STAN_KEY_HOOD_NAME + " = ?, " + /*46*/ STAN_KEY_HOOD_SAFETY + " = ?, " + /*47*/ STAN_KEY_HOOD_CBD + " = ?, "
+ /*48*/ STAN_KEY_HOOD_NEARBY + " = ?, " + /*49*/ STAN_KEY_TOURIST_RECO + " = ?, " + /*50*/ STAN_KEY_TOURIST_REASON + " = ?, " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + " = ?, "
+ /*52*/ STAN_KEY_INFO_OTHER_INFO+ " = ?, " + /*53*/ STAN_KEY_EST_DB_SCORE+ " = ?, " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + " = ?, " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + " = ?, "
+ /*56*/ STAN_KEY_BREAKFASTS + " = ?, " + /*57*/ STAN_KEY_FREE_WIFI + " = ?, " + /*58*/ STAN_KEY_DATE_UPDATED + " = ?" + " WHERE " + STAN_KEY_RECORDS_ID + " = ?";
下面是我实际的 SQLite Update 查询方法:
@Override
public void updateRecordByDatabaseId (StanRecord stanRecord, int dbID) {
Connection stanDbCon = null;
PreparedStatement stanDbPrepState = null;
try {
// [1] Make an SQL connection the STAN Records SQLite database.
stanDbCon = StanConnectConfig.getStanConnection();
// [2] Define the SQLite Statement to be used for inserting data into the database.
stanDbPrepState = stanDbCon.prepareStatement(UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
// [3] Insert the passed data into the STAN Records SQLite database (one-by-one).
stanDbPrepState.setString(1, stanRecord.getEstablishment_Name()); // Entry 1: Est_Name
stanDbPrepState.setString(2, stanRecord.getEstablishment_Type()); // Entry 2: Est_Type
stanDbPrepState.setString(3, stanRecord.getCity_Town()); // Entry 3: City_Town
stanDbPrepState.setString(4, stanRecord.getDate_Created()); // Entry 4: Date_Created
stanDbPrepState.setString(5, stanRecord.getLoc_Lat()); // Entry 5: Loc_Lat
stanDbPrepState.setString(6, stanRecord.getLoc_Long()); // Entry 6: Loc_Long
stanDbPrepState.setString(7, stanRecord.getPhys_Street_Name()); // Entry 7: Street_Name
stanDbPrepState.setString(8, stanRecord.getPhys_Erf_Number()); // Entry 8: Erf_Number
stanDbPrepState.setString(9, stanRecord.getPhys_Suburb_Name()); // Entry 9: Suburb_Name
stanDbPrepState.setString(10, stanRecord.getPhys_Address_Desc()); // Entry 10: Address_Desc
stanDbPrepState.setString(11, stanRecord.getRate_Single()); // Entry 11: Rate_Single
stanDbPrepState.setString(12, stanRecord.getRate_Double()); // Entry 12: Rate_Double
stanDbPrepState.setString(13, stanRecord.getRate_Family()); // Entry 13: Rate_Family
stanDbPrepState.setString(14, stanRecord.getRate_Vip()); // Entry 14: Rate_VIP
stanDbPrepState.setString(15, stanRecord.getContacts_Fixed()); // Entry 15: Contacts_Fixed
stanDbPrepState.setString(16, stanRecord.getContacts_Fax()); // Entry 16: Contacts_Fax
stanDbPrepState.setString(17, stanRecord.getContacts_Mobile()); // Entry 17: Contacts_Mobile
stanDbPrepState.setString(18, stanRecord.getContacts_Email()); // Entry 18: Contacts_Email
stanDbPrepState.setString(19, stanRecord.getContacts_Website()); // Entry 19: Contacts_Website
stanDbPrepState.setString(20, stanRecord.getSelf_Cater()); // Entry 20: Self_Cater
stanDbPrepState.setString(21, stanRecord.getParking_Type()); // Entry 21: Parking_Type
stanDbPrepState.setString(22, stanRecord.getParking_Shade()); // Entry 22: Parking_Shade
stanDbPrepState.setString(23, stanRecord.getParking_Bays()); // Entry 23: Parking_Bays
stanDbPrepState.setString(24, stanRecord.getParking_Rating()); // Entry 24: Parking_Rating
stanDbPrepState.setString(25, stanRecord.getRooms_Single_Units()); // Entry 25: Single_Units
stanDbPrepState.setString(26, stanRecord.getRooms_Single_Desc()); // Entry 26: Single_Desc
stanDbPrepState.setString(27, stanRecord.getRooms_Double_Units()); // Entry 27: Double_Units
stanDbPrepState.setString(28, stanRecord.getRooms_Double_Desc()); // Entry 28: Double_Desc
stanDbPrepState.setString(29, stanRecord.getRooms_Family_Units()); // Entry 29: Family_Units
stanDbPrepState.setString(30, stanRecord.getRooms_Family_Desc()); // Entry 30: Family_Desc
stanDbPrepState.setString(31, stanRecord.getRooms_Vip_Units()); // Entry 31: VIP_Units
stanDbPrepState.setString(32, stanRecord.getRooms_Vip_Desc()); // Entry 32: VIP_Desc
stanDbPrepState.setString(33, stanRecord.getRooms_Single_Double()); // Entry 33: Single_Double
stanDbPrepState.setString(34, stanRecord.getRooms_Overall_Condition()); // Entry 34: Overall_Condition
stanDbPrepState.setString(35, stanRecord.getRooms_Privacy()); // Entry 35: Room_Privacy
stanDbPrepState.setString(36, stanRecord.getRooms_Bath_Shared()); // Entry 36: Bath_Shared
stanDbPrepState.setString(37, stanRecord.getInroom_Air_Con()); // Entry 37: Air_Con
stanDbPrepState.setString(38, stanRecord.getInroom_Fridge()); // Entry 38: Room_Fridge
stanDbPrepState.setString(39, stanRecord.getInroom_Tv()); // Entry 39: Room_TV
stanDbPrepState.setString(40, stanRecord.getInroom_Bedding()); // Entry 40: Room_Bedding
stanDbPrepState.setString(41, stanRecord.getInroom_Space()); // Entry 41: Room_Size or Space
stanDbPrepState.setString(42, stanRecord.getBonus_Fac_Pool()); // Entry 42: Bonus_Pool
stanDbPrepState.setString(43, stanRecord.getBonus_Fac_Gym()); // Entry 43: Bonus_Gym
stanDbPrepState.setString(44, stanRecord.getBonus_Fac_Bar()); // Entry 44: Bonus_inHouse Bar
stanDbPrepState.setString(45, stanRecord.getHood_Name()); // Entry 45: Hood_Name
stanDbPrepState.setString(46, stanRecord.getHood_Safety()); // Entry 46: Hood_Safety
stanDbPrepState.setString(47, stanRecord.getHood_Dist_Cbd()); // Entry 47: Hood_CBD
stanDbPrepState.setString(48, stanRecord.getHood_Nearby_Attractions()); // Entry 48: Hood_Other Unknown
stanDbPrepState.setString(49, stanRecord.getTourist_Rating_Reco()); // Entry 49: Tourist_Recommendation
stanDbPrepState.setString(50, stanRecord.getTourist_Rating_Reason()); // Entry 50: Tourist_Reason
stanDbPrepState.setString(51, stanRecord.getInfo_Cancel_Policy()); // Entry 51: Cancel_Policy
stanDbPrepState.setString(52, stanRecord.getInfo_Other_Info()); // Entry 52: Other_Info
stanDbPrepState.setInt(53, stanRecord.getStan_Db_Sore()); // Entry 53: DataBase_Score
stanDbPrepState.setString(54, stanRecord.getStan_Fac_Shuttle()); // Entry 54: Shuttle_Service
stanDbPrepState.setString(55, stanRecord.getStan_Fac_Kitchen()); // Entry 55: Kitchen_Availability
stanDbPrepState.setString(56, stanRecord.getStan_Fac_Breakfast()); // Entry 56: Breakfast_Quality
stanDbPrepState.setString(57, stanRecord.getStan_Fac_Wifi()); // Entry 57: Free_WiFi
stanDbPrepState.setString(58, stanRecord.getDate_Updated()); // Entry 58: Date_Updated
// [4] Identify the location point in Stan Database.
stanDbPrepState.setInt(59, dbID);
// [5] Execute the data insertion into the Records database.
stanDbPrepState.executeUpdate();
// [6] Confirm data insert with an alert to user.
// System.out.println("\n" + UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
JOptionPane.showMessageDialog(null, UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stanDbPrepState != null) {
try {
stanDbPrepState.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stanDbCon != null) {
try {
stanDbCon.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
所有 SQLite 方法(创建、读取、插入和删除)都运行良好。只是 Update 方法不起作用。它一直执行到显示 JOptionPane 代码...
JOptionPane.showMessageDialog(null, UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
...甚至显示消息,就好像数据已成功更新一样。但是当您查看要更新的行时,没有任何更改(仍然是原始插入数据)。请帮忙 - 我已经为这段代码苦苦挣扎了一个多星期了。请注意:我对纯 Java 编程还很陌生。我正在使用 IntelliJ IDEA IDE 来开发此应用程序。任何帮助将不胜感激。提前致谢。 Shore-T!
索引 3 被设置了两次。第二次设置时,设置为int。
我正在创建一个 Java 桌面应用程序,该应用程序使用具有 50 多个数据变量的 SQLite 数据库。我有一个具有以下变量的 DatabaseHelper class:
//-- The SQLite Database Table name --//
private static final String STAN_RECORDS_TABLE = "STAN_SQLite_Records_Table"; // Primary Table - Table 1.
//-- The STAN Records DATABASE TABLE COLUMNS - or KEYS - defined here as static variables. --//
private static final String STAN_KEY_RECORDS_ID = "Stan_Records_id"; // Record 1
private static final String STAN_KEY_DATE_CREATED = "Date_Created"; // Record 2
private static final String STAN_KEY_EST_TYPE = "Stan_Est_Type"; // Record 3
private static final String STAN_KEY_CITY_TOWN = "City_Town"; // Record 4
private static final String STAN_KEY_LOC_LAT = "Loc_Lat"; // Record 5
private static final String STAN_KEY_LOC_LONG = "Loc_Long"; // Record 6
private static final String STAN_KEY_STREET_NAME = "Street_Name"; // Record 7
private static final String STAN_KEY_ERF_NUM = "Erf_Number"; // Record 8
private static final String STAN_KEY_SUBURB_NAME = "Suburb_Name"; // Record 9
private static final String STAN_KEY_ADDRESS_DESC = "Address_Desc"; // Record 10
private static final String STAN_KEY_RATE_SINGLE = "Single_Rate"; // Record 11
private static final String STAN_KEY_RATE_DOUBLE = "Double_Rate"; // Record 12
private static final String STAN_KEY_RATE_FAMILY = "Family_Rate"; // Record 13
private static final String STAN_KEY_RATE_VIP = "VIP_Rate"; // Record 14
private static final String STAN_KEY_CONTACTS_FIXED = "Fixed_Line"; // Record 15
private static final String STAN_KEY_CONTACTS_FAX = "Facsimile"; // Record 16
private static final String STAN_KEY_CONTACTS_MOBILE = "Mobile"; // Record 17
private static final String STAN_KEY_CONTACTS_EMAIL = "Email"; // Record 18
private static final String STAN_KEY_CONTACTS_WEB = "Website"; // Record 19
private static final String STAN_KEY_SELF_CATER = "Self_Cater"; // Record 20
private static final String STAN_KEY_PARKING_TYPE = "Parking_Type"; // Record 21
private static final String STAN_KEY_PARKING_SHADE = "Parking_Shade"; // Record 22
private static final String STAN_KEY_PARKING_BAYS = "Parking_Bays"; // Record 23
private static final String STAN_KEY_PARKING_RATING = "Parking_Rating"; // Record 24
private static final String STAN_KEY_SINGLE_UNITS = "Single_Units"; // Record 25
private static final String STAN_KEY_SINGLE_DESC = "Single_Desc"; // Record 26
private static final String STAN_KEY_DOUBLE_UNITS = "Double_Units"; // Record 27
private static final String STAN_KEY_DOUBLE_DESC = "Double_Desc"; // Record 28
private static final String STAN_KEY_FAMILY_UNITS = "Family_Units"; // Record 29
private static final String STAN_KEY_FAMILY_DESC = "Family_Desc"; // Record 30
private static final String STAN_KEY_VIP_UNITS = "VIP_Units"; // Record 31
private static final String STAN_KEY_VIP_DESC = "VIP_Desc"; // Record 32
private static final String STAN_KEY_SINGLE_DOUBLE = "Single_Doubles"; // Record 33
private static final String STAN_KEY_ROOM_COND = "Room_Condition"; // Record 34
private static final String STAN_KEY_ROOM_PRIVACY = "Room_Privacy"; // Record 35
private static final String STAN_KEY_BATHROOM_SHARED = "Bathroom_Shared"; // Record 36
private static final String STAN_KEY_AIR_CON = "Air_Con"; // Record 37
private static final String STAN_KEY_ROOM_FRIDGE = "Room_Fridge"; // Record 38
private static final String STAN_KEY_ROOM_TV = "Room_TV"; // Record 39
private static final String STAN_KEY_ROOM_BEDDING = "Room_Bedding"; // Record 40
private static final String STAN_KEY_ROOM_SIZE = "Room_Size"; // Record 41
private static final String STAN_KEY_BONUS_POOL = "Bonus_Pool"; // Record 42
private static final String STAN_KEY_BONUS_GYM = "Bonus_Gym"; // Record 43
private static final String STAN_KEY_BONUS_BAR = "Bonus_Bar"; // Record 44
private static final String STAN_KEY_HOOD_NAME = "Hood_Name"; // Record 45
private static final String STAN_KEY_HOOD_SAFETY = "Hood_Safety"; // Record 47
private static final String STAN_KEY_HOOD_CBD = "Hood_CBD"; // Record 48
private static final String STAN_KEY_HOOD_NEARBY = "Hood_Nearby"; // Record 49
private static final String STAN_KEY_TOURIST_RECO = "Tourist_Reco"; // Record 50
private static final String STAN_KEY_TOURIST_REASON = "Tourist_Reason"; // Record 51
private static final String STAN_KEY_INFO_CANCEL_POLICY = "Cancel_Policy"; // Record 52
private static final String STAN_KEY_INFO_OTHER_INFO = "Other_Info"; // Record 53
private static final String STAN_KEY_EST_DB_SCORE = "Est_DB_Score"; // Record 54
private static final String STAN_KEY_DATE_UPDATED = "Date_Updated"; // Record 55
private static final String STAN_KEY_SHUTTLE_SERVICE = "Shuttle_Service"; // Record 55
private static final String STAN_KEY_KITCHEN_AVAILABLE = "Kitchen"; // Record 56
private static final String STAN_KEY_BREAKFASTS = "Breakfast"; // Record 57
private static final String STAN_KEY_FREE_WIFI = "Free_Wifi"; // Record 58
private static final String STAN_KEY_EST_NAME = "Est_Name"; // Record 59
然后我有一个数据库创建字符串:
//-- STAN Records TABLE creation SQL Statement --//
private static final String CREATE_STAN_RECORDS_TABLE = "CREATE TABLE IF NOT EXISTS " + STAN_RECORDS_TABLE + " (" + /*0*/ STAN_KEY_RECORDS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ /*1*/ STAN_KEY_EST_NAME + " VARCHAR(255)," + /*2*/ STAN_KEY_EST_TYPE + " VARCHAR(255), " + /*3*/ STAN_KEY_CITY_TOWN + " VARCHAR(255), " + /*4*/ STAN_KEY_DATE_CREATED + " VARCHAR(255), "
+ /*5*/ STAN_KEY_LOC_LAT + " VARCHAR(255), " + /*6*/ STAN_KEY_LOC_LONG + " VARCHAR(255), " + /*7*/ STAN_KEY_STREET_NAME + " VARCHAR(255), "
+ /*8*/ STAN_KEY_ERF_NUM + " VARCHAR(255), " + /*9*/ STAN_KEY_SUBURB_NAME + " VARCHAR(255), " + /*10*/ STAN_KEY_ADDRESS_DESC + " VARCHAR(255), "
+ /*11*/ STAN_KEY_RATE_SINGLE + " VARCHAR(255), " + /*12*/ STAN_KEY_RATE_DOUBLE + " VARCHAR(255), " + /*13*/ STAN_KEY_RATE_FAMILY + " VARCHAR(255), "
+ /*14*/ STAN_KEY_RATE_VIP + " VARCHAR(255), " + /*15*/ STAN_KEY_CONTACTS_FIXED + " VARCHAR(255), " + /*16*/ STAN_KEY_CONTACTS_FAX + " VARCHAR(255), "
+ /*17*/ STAN_KEY_CONTACTS_MOBILE + " VARCHAR(255), " + /*18*/ STAN_KEY_CONTACTS_EMAIL + " VARCHAR(255), " + /*19*/ STAN_KEY_CONTACTS_WEB + " VARCHAR(255), "
+ /*20*/ STAN_KEY_SELF_CATER + " VARCHAR(255), " + /*21*/ STAN_KEY_PARKING_TYPE + " VARCHAR(255), " + /*22*/ STAN_KEY_PARKING_SHADE + " VARCHAR(255), "
+ /*23*/ STAN_KEY_PARKING_BAYS + " VARCHAR(255), " + /*24*/ STAN_KEY_PARKING_RATING + " VARCHAR(255), " + /*25*/ STAN_KEY_SINGLE_UNITS + " VARCHAR(255), "
+ /*26*/ STAN_KEY_SINGLE_DESC + " VARCHAR(255), " + /*27*/ STAN_KEY_DOUBLE_UNITS + " VARCHAR(255), " + /*28*/ STAN_KEY_DOUBLE_DESC + " VARCHAR(255), "
+ /*29*/ STAN_KEY_FAMILY_UNITS + " VARCHAR(255), " + /*30*/ STAN_KEY_FAMILY_DESC + " VARCHAR(255), " + /*31*/ STAN_KEY_VIP_UNITS + " VARCHAR(255), "
+ /*32*/ STAN_KEY_VIP_DESC + " VARCHAR(255), " + /*33*/ STAN_KEY_SINGLE_DOUBLE + " VARCHAR(255), " + /*34*/ STAN_KEY_ROOM_COND + " VARCHAR(255), "
+ /*35*/ STAN_KEY_ROOM_PRIVACY + " VARCHAR(255), " + /*36*/ STAN_KEY_BATHROOM_SHARED + " VARCHAR(255), " + /*37*/ STAN_KEY_AIR_CON + " VARCHAR(255), "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + " VARCHAR(255), " + /*39*/ STAN_KEY_ROOM_TV + " VARCHAR(255), " + /*40*/ STAN_KEY_ROOM_BEDDING + " VARCHAR(255), "
+ /*41*/ STAN_KEY_ROOM_SIZE + " VARCHAR(255), " + /*42*/ STAN_KEY_BONUS_POOL + " VARCHAR(255), " + /*43*/ STAN_KEY_BONUS_GYM + " VARCHAR(255), "
+ /*44*/ STAN_KEY_BONUS_BAR + " VARCHAR(255), " + /*45*/ STAN_KEY_HOOD_NAME + " VARCHAR(255), " + /*46*/ STAN_KEY_HOOD_SAFETY + " VARCHAR(255), "
+ /*47*/ STAN_KEY_HOOD_CBD + " VARCHAR(255), " + /*48*/ STAN_KEY_HOOD_NEARBY + " VARCHAR(255), " + /*49*/ STAN_KEY_TOURIST_RECO + " VARCHAR(255), "
+ /*50*/ STAN_KEY_TOURIST_REASON + " VARCHAR(255), " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + " VARCHAR(255), " + /*52*/ STAN_KEY_INFO_OTHER_INFO+ " VARCHAR(255), "
+ /*53*/ STAN_KEY_EST_DB_SCORE + " INTEGER, " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + " VARCHAR(255), " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + " VARCHAR(255), "
+ /*56*/ STAN_KEY_BREAKFASTS + " VARCHAR(255), " + /*57*/ STAN_KEY_FREE_WIFI + " VARCHAR(255), " + /*58*/ STAN_KEY_DATE_UPDATED + " VARCHAR(255));";
...和记录插入字符串:
private static final String INSERT_ONE_COMPLETE_STAN_RECORDS_ENTRY = "INSERT INTO " + STAN_RECORDS_TABLE + " (" + /*1*/ STAN_KEY_EST_NAME + ", " + /*2*/ STAN_KEY_EST_TYPE + ", "
+ /*3*/ STAN_KEY_CITY_TOWN + ", " + /*4*/ STAN_KEY_DATE_CREATED + ", " + /*5*/ STAN_KEY_LOC_LAT + ", " + /*6*/ STAN_KEY_LOC_LONG + ", " + /*7*/ STAN_KEY_STREET_NAME + ", "
+ /*8*/ STAN_KEY_ERF_NUM + ", " + /*9*/ STAN_KEY_SUBURB_NAME + ", " + /*10*/ STAN_KEY_ADDRESS_DESC + ", " + /*11*/ STAN_KEY_RATE_SINGLE + ", " + /*12*/ STAN_KEY_RATE_DOUBLE + ", "
+ /*13*/ STAN_KEY_RATE_FAMILY + ", " + /*14*/ STAN_KEY_RATE_VIP + ", " + /*15*/ STAN_KEY_CONTACTS_FIXED + ", " + /*16*/ STAN_KEY_CONTACTS_FAX + ", " + /*17*/ STAN_KEY_CONTACTS_MOBILE + ", "
+ /*18*/ STAN_KEY_CONTACTS_EMAIL + ", " + /*19*/ STAN_KEY_CONTACTS_WEB + ", " + /*20*/ STAN_KEY_SELF_CATER + ", " + /*21*/ STAN_KEY_PARKING_TYPE + ", " + /*22*/ STAN_KEY_PARKING_SHADE + ", "
+ /*23*/ STAN_KEY_PARKING_BAYS + ", " + /*24*/ STAN_KEY_PARKING_RATING + ", " + /*25*/ STAN_KEY_SINGLE_UNITS + ", " + /*26*/ STAN_KEY_SINGLE_DESC + ", " + /*27*/ STAN_KEY_DOUBLE_UNITS + ", "
+ /*28*/ STAN_KEY_DOUBLE_DESC + ", " + /*29*/ STAN_KEY_FAMILY_UNITS + ", " + /*30*/ STAN_KEY_FAMILY_DESC + ", " + /*31*/ STAN_KEY_VIP_UNITS + ", " + /*32*/ STAN_KEY_VIP_DESC + ", "
+ /*33*/ STAN_KEY_SINGLE_DOUBLE + ", " + /*34*/ STAN_KEY_ROOM_COND + ", " + /*35*/ STAN_KEY_ROOM_PRIVACY + ", " + /*36*/ STAN_KEY_BATHROOM_SHARED + ", " + /*37*/ STAN_KEY_AIR_CON + ", "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + ", " + /*39*/ STAN_KEY_ROOM_TV + ", " + /*40*/ STAN_KEY_ROOM_BEDDING + ", " + /*41*/ STAN_KEY_ROOM_SIZE + ", " + /*42*/ STAN_KEY_BONUS_POOL + ", "
+ /*43*/ STAN_KEY_BONUS_GYM + ", " + /*44*/ STAN_KEY_BONUS_BAR + ", " + /*45*/ STAN_KEY_HOOD_NAME + ", " + /*46*/ STAN_KEY_HOOD_SAFETY + ", " + /*47*/ STAN_KEY_HOOD_CBD + ", "
+ /*48*/ STAN_KEY_HOOD_NEARBY + ", " + /*49*/ STAN_KEY_TOURIST_RECO + ", " + /*50*/ STAN_KEY_TOURIST_REASON + ", " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + ", "
+ /*52*/ STAN_KEY_INFO_OTHER_INFO+ ", " + /*53*/ STAN_KEY_EST_DB_SCORE+ ", " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + ", " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + ", "
+ /*56*/ STAN_KEY_BREAKFASTS + ", " + /*57*/ STAN_KEY_FREE_WIFI + ", " + /*58*/ STAN_KEY_DATE_UPDATED + ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
+ "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
...以及记录更新字符串(这是问题!!):
private static final String UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY = "UPDATE " + STAN_RECORDS_TABLE + " SET " + /*1*/ STAN_KEY_EST_NAME + " = ?, " + /*2*/ STAN_KEY_EST_TYPE + " = ?, "
+ /*3*/ STAN_KEY_CITY_TOWN + " = ?, " + /*4*/ STAN_KEY_DATE_CREATED + " = ?, " + /*5*/ STAN_KEY_LOC_LAT + " = ?, " + /*6*/ STAN_KEY_LOC_LONG + " = ?, " + /*7*/ STAN_KEY_STREET_NAME + " = ?, "
+ /*8*/ STAN_KEY_ERF_NUM + " = ?, " + /*9*/ STAN_KEY_SUBURB_NAME + " = ?, " + /*10*/ STAN_KEY_ADDRESS_DESC + " = ?, " + /*11*/ STAN_KEY_RATE_SINGLE + " = ?, " + /*12*/ STAN_KEY_RATE_DOUBLE + " = ?, "
+ /*13*/ STAN_KEY_RATE_FAMILY + " = ?, " + /*14*/ STAN_KEY_RATE_VIP + " = ?, " + /*15*/ STAN_KEY_CONTACTS_FIXED + " = ?, " + /*16*/ STAN_KEY_CONTACTS_FAX + " = ?, " + /*17*/ STAN_KEY_CONTACTS_MOBILE + " = ?, "
+ /*18*/ STAN_KEY_CONTACTS_EMAIL + " = ?, " + /*19*/ STAN_KEY_CONTACTS_WEB + " = ?, " + /*20*/ STAN_KEY_SELF_CATER + " = ?, " + /*21*/ STAN_KEY_PARKING_TYPE + " = ?, " + /*22*/ STAN_KEY_PARKING_SHADE + " = ?, "
+ /*23*/ STAN_KEY_PARKING_BAYS + " = ?, " + /*24*/ STAN_KEY_PARKING_RATING + " = ?, " + /*25*/ STAN_KEY_SINGLE_UNITS + " = ?, " + /*26*/ STAN_KEY_SINGLE_DESC + " = ?, " + /*27*/ STAN_KEY_DOUBLE_UNITS + " = ?, "
+ /*28*/ STAN_KEY_DOUBLE_DESC + " = ?, " + /*29*/ STAN_KEY_FAMILY_UNITS + " = ?, " + /*30*/ STAN_KEY_FAMILY_DESC + " = ?, " + /*31*/ STAN_KEY_VIP_UNITS + " = ?, " + /*32*/ STAN_KEY_VIP_DESC + " = ?, "
+ /*33*/ STAN_KEY_SINGLE_DOUBLE + " = ?, " + /*34*/ STAN_KEY_ROOM_COND + " = ?, " + /*35*/ STAN_KEY_ROOM_PRIVACY + " = ?, " + /*36*/ STAN_KEY_BATHROOM_SHARED + " = ?, " + /*37*/ STAN_KEY_AIR_CON + " = ?, "
+ /*38*/ STAN_KEY_ROOM_FRIDGE + " = ?, " + /*39*/ STAN_KEY_ROOM_TV + " = ?, " + /*40*/ STAN_KEY_ROOM_BEDDING + " = ?, " + /*41*/ STAN_KEY_ROOM_SIZE + " = ?, " + /*42*/ STAN_KEY_BONUS_POOL + " = ?, "
+ /*43*/ STAN_KEY_BONUS_GYM + " = ?, " + /*44*/ STAN_KEY_BONUS_BAR + " = ?, " + /*45*/ STAN_KEY_HOOD_NAME + " = ?, " + /*46*/ STAN_KEY_HOOD_SAFETY + " = ?, " + /*47*/ STAN_KEY_HOOD_CBD + " = ?, "
+ /*48*/ STAN_KEY_HOOD_NEARBY + " = ?, " + /*49*/ STAN_KEY_TOURIST_RECO + " = ?, " + /*50*/ STAN_KEY_TOURIST_REASON + " = ?, " + /*51*/ STAN_KEY_INFO_CANCEL_POLICY + " = ?, "
+ /*52*/ STAN_KEY_INFO_OTHER_INFO+ " = ?, " + /*53*/ STAN_KEY_EST_DB_SCORE+ " = ?, " + /*54*/ STAN_KEY_SHUTTLE_SERVICE + " = ?, " + /*55*/ STAN_KEY_KITCHEN_AVAILABLE + " = ?, "
+ /*56*/ STAN_KEY_BREAKFASTS + " = ?, " + /*57*/ STAN_KEY_FREE_WIFI + " = ?, " + /*58*/ STAN_KEY_DATE_UPDATED + " = ?" + " WHERE " + STAN_KEY_RECORDS_ID + " = ?";
下面是我实际的 SQLite Update 查询方法:
@Override
public void updateRecordByDatabaseId (StanRecord stanRecord, int dbID) {
Connection stanDbCon = null;
PreparedStatement stanDbPrepState = null;
try {
// [1] Make an SQL connection the STAN Records SQLite database.
stanDbCon = StanConnectConfig.getStanConnection();
// [2] Define the SQLite Statement to be used for inserting data into the database.
stanDbPrepState = stanDbCon.prepareStatement(UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
// [3] Insert the passed data into the STAN Records SQLite database (one-by-one).
stanDbPrepState.setString(1, stanRecord.getEstablishment_Name()); // Entry 1: Est_Name
stanDbPrepState.setString(2, stanRecord.getEstablishment_Type()); // Entry 2: Est_Type
stanDbPrepState.setString(3, stanRecord.getCity_Town()); // Entry 3: City_Town
stanDbPrepState.setString(4, stanRecord.getDate_Created()); // Entry 4: Date_Created
stanDbPrepState.setString(5, stanRecord.getLoc_Lat()); // Entry 5: Loc_Lat
stanDbPrepState.setString(6, stanRecord.getLoc_Long()); // Entry 6: Loc_Long
stanDbPrepState.setString(7, stanRecord.getPhys_Street_Name()); // Entry 7: Street_Name
stanDbPrepState.setString(8, stanRecord.getPhys_Erf_Number()); // Entry 8: Erf_Number
stanDbPrepState.setString(9, stanRecord.getPhys_Suburb_Name()); // Entry 9: Suburb_Name
stanDbPrepState.setString(10, stanRecord.getPhys_Address_Desc()); // Entry 10: Address_Desc
stanDbPrepState.setString(11, stanRecord.getRate_Single()); // Entry 11: Rate_Single
stanDbPrepState.setString(12, stanRecord.getRate_Double()); // Entry 12: Rate_Double
stanDbPrepState.setString(13, stanRecord.getRate_Family()); // Entry 13: Rate_Family
stanDbPrepState.setString(14, stanRecord.getRate_Vip()); // Entry 14: Rate_VIP
stanDbPrepState.setString(15, stanRecord.getContacts_Fixed()); // Entry 15: Contacts_Fixed
stanDbPrepState.setString(16, stanRecord.getContacts_Fax()); // Entry 16: Contacts_Fax
stanDbPrepState.setString(17, stanRecord.getContacts_Mobile()); // Entry 17: Contacts_Mobile
stanDbPrepState.setString(18, stanRecord.getContacts_Email()); // Entry 18: Contacts_Email
stanDbPrepState.setString(19, stanRecord.getContacts_Website()); // Entry 19: Contacts_Website
stanDbPrepState.setString(20, stanRecord.getSelf_Cater()); // Entry 20: Self_Cater
stanDbPrepState.setString(21, stanRecord.getParking_Type()); // Entry 21: Parking_Type
stanDbPrepState.setString(22, stanRecord.getParking_Shade()); // Entry 22: Parking_Shade
stanDbPrepState.setString(23, stanRecord.getParking_Bays()); // Entry 23: Parking_Bays
stanDbPrepState.setString(24, stanRecord.getParking_Rating()); // Entry 24: Parking_Rating
stanDbPrepState.setString(25, stanRecord.getRooms_Single_Units()); // Entry 25: Single_Units
stanDbPrepState.setString(26, stanRecord.getRooms_Single_Desc()); // Entry 26: Single_Desc
stanDbPrepState.setString(27, stanRecord.getRooms_Double_Units()); // Entry 27: Double_Units
stanDbPrepState.setString(28, stanRecord.getRooms_Double_Desc()); // Entry 28: Double_Desc
stanDbPrepState.setString(29, stanRecord.getRooms_Family_Units()); // Entry 29: Family_Units
stanDbPrepState.setString(30, stanRecord.getRooms_Family_Desc()); // Entry 30: Family_Desc
stanDbPrepState.setString(31, stanRecord.getRooms_Vip_Units()); // Entry 31: VIP_Units
stanDbPrepState.setString(32, stanRecord.getRooms_Vip_Desc()); // Entry 32: VIP_Desc
stanDbPrepState.setString(33, stanRecord.getRooms_Single_Double()); // Entry 33: Single_Double
stanDbPrepState.setString(34, stanRecord.getRooms_Overall_Condition()); // Entry 34: Overall_Condition
stanDbPrepState.setString(35, stanRecord.getRooms_Privacy()); // Entry 35: Room_Privacy
stanDbPrepState.setString(36, stanRecord.getRooms_Bath_Shared()); // Entry 36: Bath_Shared
stanDbPrepState.setString(37, stanRecord.getInroom_Air_Con()); // Entry 37: Air_Con
stanDbPrepState.setString(38, stanRecord.getInroom_Fridge()); // Entry 38: Room_Fridge
stanDbPrepState.setString(39, stanRecord.getInroom_Tv()); // Entry 39: Room_TV
stanDbPrepState.setString(40, stanRecord.getInroom_Bedding()); // Entry 40: Room_Bedding
stanDbPrepState.setString(41, stanRecord.getInroom_Space()); // Entry 41: Room_Size or Space
stanDbPrepState.setString(42, stanRecord.getBonus_Fac_Pool()); // Entry 42: Bonus_Pool
stanDbPrepState.setString(43, stanRecord.getBonus_Fac_Gym()); // Entry 43: Bonus_Gym
stanDbPrepState.setString(44, stanRecord.getBonus_Fac_Bar()); // Entry 44: Bonus_inHouse Bar
stanDbPrepState.setString(45, stanRecord.getHood_Name()); // Entry 45: Hood_Name
stanDbPrepState.setString(46, stanRecord.getHood_Safety()); // Entry 46: Hood_Safety
stanDbPrepState.setString(47, stanRecord.getHood_Dist_Cbd()); // Entry 47: Hood_CBD
stanDbPrepState.setString(48, stanRecord.getHood_Nearby_Attractions()); // Entry 48: Hood_Other Unknown
stanDbPrepState.setString(49, stanRecord.getTourist_Rating_Reco()); // Entry 49: Tourist_Recommendation
stanDbPrepState.setString(50, stanRecord.getTourist_Rating_Reason()); // Entry 50: Tourist_Reason
stanDbPrepState.setString(51, stanRecord.getInfo_Cancel_Policy()); // Entry 51: Cancel_Policy
stanDbPrepState.setString(52, stanRecord.getInfo_Other_Info()); // Entry 52: Other_Info
stanDbPrepState.setInt(53, stanRecord.getStan_Db_Sore()); // Entry 53: DataBase_Score
stanDbPrepState.setString(54, stanRecord.getStan_Fac_Shuttle()); // Entry 54: Shuttle_Service
stanDbPrepState.setString(55, stanRecord.getStan_Fac_Kitchen()); // Entry 55: Kitchen_Availability
stanDbPrepState.setString(56, stanRecord.getStan_Fac_Breakfast()); // Entry 56: Breakfast_Quality
stanDbPrepState.setString(57, stanRecord.getStan_Fac_Wifi()); // Entry 57: Free_WiFi
stanDbPrepState.setString(58, stanRecord.getDate_Updated()); // Entry 58: Date_Updated
// [4] Identify the location point in Stan Database.
stanDbPrepState.setInt(59, dbID);
// [5] Execute the data insertion into the Records database.
stanDbPrepState.executeUpdate();
// [6] Confirm data insert with an alert to user.
// System.out.println("\n" + UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
JOptionPane.showMessageDialog(null, UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (stanDbPrepState != null) {
try {
stanDbPrepState.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stanDbCon != null) {
try {
stanDbCon.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
所有 SQLite 方法(创建、读取、插入和删除)都运行良好。只是 Update 方法不起作用。它一直执行到显示 JOptionPane 代码...
JOptionPane.showMessageDialog(null, UPDATE_ONE_COMPLETE_STAN_RECORDS_ENTRY);
...甚至显示消息,就好像数据已成功更新一样。但是当您查看要更新的行时,没有任何更改(仍然是原始插入数据)。请帮忙 - 我已经为这段代码苦苦挣扎了一个多星期了。请注意:我对纯 Java 编程还很陌生。我正在使用 IntelliJ IDEA IDE 来开发此应用程序。任何帮助将不胜感激。提前致谢。 Shore-T!
索引 3 被设置了两次。第二次设置时,设置为int。