org.h2.jdbc.JdbcSQLException: 列 “Salman” 未找到;

2022-09-02 19:44:08

我已尝试在我的春季应用程序中运行以下测试。

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes=App1Application.class)
@Sql(scripts="customerTest.sql")
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)

public class customerTest {


    @Autowired 
    customerRepository  customerDB;

    @Test
    public void countRecords(){

        assertThat(customerDB.count(),is(2l));

    }   
}

客户测试.sql文件我有:

insert into customer(id,name,lastname) values(1,"name","lastname");

这是我的客户

@Entity
@Data

public class customer {

    @Id
    @GeneratedValue
    int id;

    String name;
    String lastname;
    }

我也使用jpa

public interface customerRepository  extends JpaRepository<customer,Long>{

}

问题是,当我运行测试时,我面临错误:

 org.h2.jdbc.JdbcSQLException: Column "Salman" not found; SQL statement:
insert into customer(id,name,lastname) values(1,"name","lastname")

同时,“萨勒曼”是一个值,而不是一列?

请注意,我正在使用spring-mvc,所以没有数据库,只有我的模型()由代码制作。customer


答案 1

编译器做出此类错误的行为对我来说仍然是一个问题,但我设法使用这个单引号而不是双引号来处理这个错误''""

我用这个

insert into customer(id,name,lastname) values(1,'name','Lastname')

而不是

 insert into customer(id,name,lastname) values(1,"name","Lastname")

答案 2

尝试使用“”(单引号)而不是“”(双引号)。我认为这是H2库中的问题


推荐