SQLite 自动增量 - 如何插入值? [英] SQLite autoincrement - How to insert values?
本文介绍了SQLite 自动增量 - 如何插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我生成了一个 SQLite 表(在 Java 中):
I generate a SQLite table (in java):
create table participants (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, col1,col2);
之后我尝试使用 INSERT 命令添加行:
afterwards I try to add rows using the INSERT comand:
insert into participants values ("bla","blub");
我收到错误:
java.sql.SQLException: table participants has 3 columns but 2 values were supplied
我以为行ID会自动生成,但似乎我错过了什么.
I thought the row id would be generated automatically, but it seems that I miss anything.
我尝试了另一种解决方案:
I tried another solution:
PreparedStatement prep = conn.prepareStatement("insert into participants values (?,?,?);");
Integer n = null;
prep.setInt(1,n);
prep.setString(2, "bla");
prep.setString(3, "blub");
prep.addBatch();
prep.executeBatch();
结果我在prep.setInt(1,n);"处收到了一个空指针异常
as result I received a null pointer exception at "prep.setInt(1,n);"
你看到错误了吗?
推荐答案
您是否尝试过指出您传递的参数应该与表的哪些字段相关?
Have you tried indicating to which fields of the table the parameters you are passing are supposed to be related?
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
在你的情况下可能是这样的:
In your case maybe something like:
INSERT INTO participants(col1, col2) VALUES ("bla","blub");
这篇关于SQLite 自动增量 - 如何插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文