Skip to content
Advertisement

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

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;

When I insert the values and run the code, it shows me

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

Error

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

could someone explain for me? thank you

Advertisement

Answer

Update your SQL statement to use columns name like this:

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

, best practice to use PreparedStatement to avoid SQL Injection

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement