SQLite自动增量-如何插入值? [英] SQLite autoincrement - How to insert values?

查看:137
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆