Harry :
I'm trying to insert a value into only one column. How can I do this without requiring to enter in all other columns' values?
PreparedStatement ps = DbHelp.prepareStatement("INSERT INTO Player_Data VALUES (?)", db.getConnection());
ps.setString(1, e.getPlayer().getUniqueId().toString());
ps.executeUpdate();
I use this to add a column to the existing table:
String updateTable = "ALTER TABLE Player_Data ADD COLUMN " + name + " int(10) NULL;";
I expected this to only insert into the table on the first value and leave the others as null. But I actually recieve this error message: [SQLITE_ERROR] SQL error or missing database (table Player_Data has 3 columns but 1 values were supplied)
I understand that it's asking me to input values for the multiple columns but I need to only insert it into one and leave the rest as null or preferably have a default value.
Lukasz Szozda :
You should avoid "blind inserts" and explicitly specify column list:
INSERT INTO Player_Data(column_name) VALUES (?);
-- this would work as long as other columns has:
-- identity property/default constraint/nullable