Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

SQLite and id parameter

 
Greenhorn
Posts: 24
1
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have created a database with SQlite - file created - table view works -

but when I try to add new data (row) a error appears ...



Insert statement





If I put (NULL, 'Paul', '10.10.2032', 'California', 'old') for id .. then  A NOT NULL constraint failed (NOT NULL constraint failed: PEOPLE.ID) appears

Any ideas?

Edit: If I use ID INT PRIMARY KEY   AUTOINCREMENT  NOT NULL - not null error appears also

In IntelliJ IDEA  id, Info and Autoincrement looks different




 
Saloon Keeper
Posts: 7175
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is that you are telling it that you're going to pass an ID yet you don't. So, don't tell it to expect an ID.
String sql = "INSERT INTO BEWOHNER (NAME,DATE,ACTION, INFO) VALUES ('Paul', '10.10.2032', 'California', 'supi')";

It's either that or tell it to expect an ID and give it null.
 
Rancher
Posts: 4587
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have set the field to AUTOINCREMENT then you don't need to provide it at all.
That includes in the list of fields in the INSERT statement.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic