I want to insert into my name stud
in which foreign key is t_id
which is primary key in table (teacher) so I want to know the query for that.
我想插入我的名称stud,其中外键是t_id,这是表(教师)中的主键,所以我想知道查询。
INSERT into stud where s_id,Name,t_id,username,password where s_id="+s_id)
this is the query i am writing in jsp page...but it is giving me the error
这是我在jsp页面中写的查询...但它给了我错误
Cannot add or update a child row: a foreign key constraint fails (`userdb`.`stud`, CONSTRAINT `stud_ibfk_1` FOREIGN KEY (`t_id`) REFERENCES `teachers` (`t_id`));
1 个解决方案
#1
0
("INSERT INTO stud(s_id,Name,t_id,username,password)
VALUES ( " + s_id + "," + Name + "," + t_id + "," + username + "," + password + ")")
This is the correct parameterized INSERT query syntax.
这是正确的参数化INSERT查询语法。
Your query had two WHERE clauses which were written incorrectly, plus your VALUES clause was not there, plus you didn't mention the column names explicitly in your syntax. Hence, your query doesn't make any sense at all.
您的查询有两个WHERE子句写得不正确,加上您的VALUES子句不存在,另外您没有在语法中明确提到列名。因此,您的查询根本没有任何意义。
p.s. I used dummy data. Insert appropriate and relevant data in your query. Also, I assumed your parameter names are exactly the same as your columns' names. Please modify your parameters according to your code if necessary.
附:我用虚拟数据。在查询中插入适当的相关数据。此外,我假设您的参数名称与列的名称完全相同。如有必要,请根据您的代码修改参数。
#1
0
("INSERT INTO stud(s_id,Name,t_id,username,password)
VALUES ( " + s_id + "," + Name + "," + t_id + "," + username + "," + password + ")")
This is the correct parameterized INSERT query syntax.
这是正确的参数化INSERT查询语法。
Your query had two WHERE clauses which were written incorrectly, plus your VALUES clause was not there, plus you didn't mention the column names explicitly in your syntax. Hence, your query doesn't make any sense at all.
您的查询有两个WHERE子句写得不正确,加上您的VALUES子句不存在,另外您没有在语法中明确提到列名。因此,您的查询根本没有任何意义。
p.s. I used dummy data. Insert appropriate and relevant data in your query. Also, I assumed your parameter names are exactly the same as your columns' names. Please modify your parameters according to your code if necessary.
附:我用虚拟数据。在查询中插入适当的相关数据。此外,我假设您的参数名称与列的名称完全相同。如有必要,请根据您的代码修改参数。