'java.sql.SQLIntegrityConstraintViolationException: Column 'language_id' cannot be null
In an attempt to make a Java servlet to implement add functionality, the following error shows up in the console of Eclipse:
java.sql.SQLIntegrityConstraintViolationException: Column 'language_id' cannot be null
Written below is my attempt of preparing the PreparedStatement
PreparedStatement ps=con.prepareStatement(
"INSERT INTO film (title,release_year,special_features,rating,description,language_id)" +
" VALUES (?,?,?,?,?,(SELECT language_id FROM `language` WHERE `name`=?));");
ps.setString(1,titleValue);
ps.setString(2,releaseYearValue);
ps.setString(3,specialFeaturesValue);
ps.setString(4,ratingsValue);
ps.setString(5,descriptionValue);
ps.setString(6,languageValue);
int i = ps.executeUpdate();
The table structure in MySQL DB is as follows:
FILM TABLE -> title | description | special_features | release_year | rating | language_id
LANGUAGE TABLE -> language_id | name
The language_id of FILM table is the foreign key of the language_id primary column of LANGUAGE table
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
