Reputation: 1
I have derby database with table TRIPS. I have 10 columns, but 2 columns:FAIR and TIP should be inserted separately (later when trip on taxi is finished).
Can you please help me to adjust SQL code?
I have this code and it is not working now:
public boolean saveInDB2(String id, String amount, String tip) {
String writeString = "INSERT INTO TRIPS(FAIR, TIP) VALUES ('" + amount +"', '"+ tip +"')" + "WHERE ID = '"+ id +"'";
try {
st.executeUpdate(writeString);
} catch (SQLException sqle){
return false;
}
return true;
}
Upvotes: 0
Views: 559
Reputation: 81
Typically for an existing row, you wouldn't use an INSERT
, but rather would use an UPDATE
statement. INSERT
statements are for new records.
Insert: https://www.w3schools.com/sql/sql_insert.asp Update: https://www.w3schools.com/sql/sql_update.asp
Upvotes: 1