gpt4 book ai didi

java.sql.SQLSyntaxErrorException : ORA-00947: not enough values

转载 作者:行者123 更新时间:2023-12-01 16:58:50 25 4
gpt4 key购买 nike

System.out.println("Enter the code: ");
Code=input.next();
System.out.println("Enter the title: ");
Title=input.next();
System.out.println("Enter the semster: ");
Semester=input.next();
System.out.println("Enter the year: ");
Year=input.next();
System.out.println("Enter the grade: ");
Grade=input.next();

String insertStatement ="insert into Courses values('"+Code+"'+'"+Title+"'+'"+Semester+"'+'"+Year+"'+'"+Grade+"')";
System.out.println(insertStatement);
s.execute(insertStatement);
continue;

当我插入值并运行代码时,它会显示

insert into Courses values('GET'+'CS'+'Fall'+'2016'+'C+')

错误

java.sql.SQLSyntaxErrorException: ORA-00947: not enough values

有人可以帮我解释一下吗?谢谢

最佳答案

更新您的 SQL 语句以使用如下所示的列名称:

String insertStatement = "INSERT INTO Courses (codeColName, titleColName, semesterColName, yearColName, gradeColName)"
+ "VALUES ('" + code + "', '" + title + "', '" + semester + "', '" + year + "', '" + grade + "')";

,使用 PreparedStatement 避免 SQL 注入(inject)的最佳实践

关于java.sql.SQLSyntaxErrorException : ORA-00947: not enough values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61545192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com