我正在尝试仅将值插入一列。无需输入所有其他列的值怎么办?
PreparedStatement ps = DbHelp.prepareStatement("INSERT INTO Player_Data VALUES (?)", db.getConnection());
ps.setString(1, e.getPlayer().getUniqueId().toString());
ps.executeUpdate();
我用它在现有表中添加一列:
String updateTable = "ALTER TABLE Player_Data ADD COLUMN " + name + " int(10) NULL;";
我希望这只会在第一个值上插入表中,而将其他值保留为null。但我实际上收到此错误消息:
[SQLITE_ERROR] SQL error or missing database (table Player_Data has 3 columns but 1 values were supplied)
我知道这是在要求我为多列输入值,但是我只需要将其插入其中一列,其余的保留为null或最好具有默认值即可。
答案 0 :(得分:2)
您应避免使用"blind inserts"并明确指定列列表:
INSERT INTO Player_Data(column_name) VALUES (?);
-- this would work as long as other columns has:
-- identity property/default constraint/nullable