filemonczyk filemonczyk - 10 months ago 68
SQL Question

SQL error while running script with spring boot

Im trying to populate my database as I start my project:

  1. spring-boot

  2. h2 embedded database

this is the script:


here is my entity in java:

public class Vet extends BaseClass{

// @Id
// @GeneratedValue
// private int id;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;

public class BaseClass {

@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

public int getId() {
return id;

public void setId(int id) { = id;

and as I start spring , this is the stacktrace:

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO 'VET'[*] VALUES (1, 'AAAA', 'BBBB')"; expected "identifier"; SQL statement:
INSERT INTO 'VET' VALUES (1, 'AAAA', 'BBBB') [42001-192]
at org.h2.message.DbException.getJdbcSQLException( ~[h2-1.4.192.jar:1.4.192]
at org.h2.message.DbException.getSyntaxError( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.readIdentifierWithSchema( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.readTableOrView( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.parseInsert( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.parsePrepared( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.parse( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.parse( ~[h2-1.4.192.jar:1.4.192]
at org.h2.command.Parser.prepareCommand( ~[h2-1.4.192.jar:1.4.192]
at org.h2.engine.Session.prepareLocal( ~[h2-1.4.192.jar:1.4.192]
at org.h2.engine.Session.prepareCommand( ~[h2-1.4.192.jar:1.4.192]
at org.h2.jdbc.JdbcConnection.prepareCommand( ~[h2-1.4.192.jar:1.4.192]
at org.h2.jdbc.JdbcStatement.executeInternal( ~[h2-1.4.192.jar:1.4.192]
at org.h2.jdbc.JdbcStatement.execute( ~[h2-1.4.192.jar:1.4.192]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript( ~[spring-jdbc-4.2.7.RELEASE.jar:4.2.7.RELEASE]
... 67 common frames omitted

Of course the name of the script is data.sql and its located in resources folder, its obviously reading the script accordingly to stack trace. I dont understand the part with identifier


ok so i tried something like this:

INSERT INTO VET('id', 'first_name', 'last_name') VALUES (1, 'AAAA', 'BBBB');

and thats the error

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "INSERT INTO VET('id'[*], 'first_name', 'last_name') VALUES (1, 'AAAA', 'BBBB')"; expected "identifier"; SQL statement:
INSERT INTO VET('id', 'first_name', 'last_name') VALUES (1, 'AAAA', 'BBBB') [42001-192]

but when i go with:


build is succesfull

so for educational purposes only why the first option gives error?

Jay Jay
Answer Source

You shouldn't have quotes around your column names or table names.

INSERT INTO VET(id, first_name, last_name) VALUES (1, 'AAAA', 'BBBB')