简体   繁体   中英

org.h2.jdbc.JdbcSQLSyntaxErrorException: Column not found; SQL statement [SPRINGBOOT]

I've recently started using Spring Boot: I'm currently using:

  • Spring Tool Suite 4 (Spring Boot version 2.6.2)
  • JAVA 8
  • H2 Console

My goal: Display each of my Student(model) values respective to its type:

Ex:

  • ID: 1,2,3,...
  • NAME: Bob Kim, Marley Z,...
  • DEPARTMENT: Computer Science, Nursing,...
  • UPDATEDBY: chopp3r
  • UPDATEDON: 2022-01-17

Student.java (Model Class):

@Entity
public class Student 
{
    @Id
    private Integer Id;
    private String name;
    private String department;
    private String updatedBy;
    @DateTimeFormat(pattern="yyy-MM-dd")
    private Date updatedOn;
    
    public Student()
    {
        
    }

    public Student(Integer id, String name, String department, String updatedBy, Date updatedOn) {
        super();
        Id = id;
        this.name = name;
        this.department = department;
        this.updatedBy = updatedBy;
        this.updatedOn = updatedOn;
    }

    GETTERS/SETTERS METHODS...
    TOSTRING METHOD...
    
}

Dependencies i'm using:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.4.1</version>
        </dependency>

data.sql that works without ERROR but gives me diff values in h2-console:

insert into student values (1,'Bob Kim','Computer Science','chopp3r','2022-01-17');
insert into student values (2,'Marley Z','Nursing','chopp3r','2022-01-17');
insert into student values (3,'Cyka Blyat','Russian Literature','chopp3r','2022-01-17');

The following picture is what shows in H2-Console and as you notice the DEPARTMENT and NAME column is swapped: 在此处输入图像描述

but if I run the Spring Boot Application with the following data.sql:

insert into student (id,name,department,updatedBy,updatedOn) values (1,'Bob Kim','Computer Science','chopp3r','2022-01-17');
insert into student (id,name,department,updatedBy,updatedOn) values (2,'Marley Z','Nursing','chopp3r','2022-01-17');
insert into student (id,name,department,updatedBy,updatedOn) values (3,'Cyka Blyat','Russian Literature','chopp3r','2022-01-17');

I get an error saying:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "UPDATEDBY" not found; SQL statement:
insert into student (id,name,department,updatedBy,updatedOn) values (1,'Bob Kim','Computer Science','chopp3r','2022-01-17') [42122-200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:453) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.message.DbException.get(DbException.java:181) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.table.Table.getColumn(Table.java:703) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseColumn(Parser.java:1450) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseColumnList(Parser.java:1435) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseInsertGivenTable(Parser.java:1804) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parseInsert(Parser.java:1749) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parsePrepared(Parser.java:954) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:843) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.parse(Parser.java:815) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.command.Parser.prepareCommand(Parser.java:738) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareLocal(Session.java:657) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.engine.Session.prepareCommand(Session.java:595) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1235) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:212) ~[h2-1.4.200.jar:1.4.200]
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:201) ~[h2-1.4.200.jar:1.4.200]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94) ~[HikariCP-4.0.3.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-4.0.3.jar:na]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:261) ~[spring-jdbc-5.3.14.jar:5.3.14]
    ... 28 common frames omitted

I tried searching for solutions whether it might be reserved words affecting my program or adding DATABASE_TO_UPPER=FALSE in my spring.datasource.url but I still get the same error that it wouldn't be able to find my updatedBy column.

Please criticize me if i'm doing something wrong or missing any spring boot info.

Ok nevermind. I found a solution that worked for me. I put @Column(name = " ") on my Student.java class on all my values and that way the columns were read through data.sql file. Sorry for the inconvenience everyone, If there is an alternative way or still an error I need to fix. please feel free to contribute.

Thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM