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注入关于java - java.sql.SQLSyntaxErrorException:ORA-00947:值不足,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61545192/