gpt4 book ai didi

java - org.h2.jdbc.JdbcSQL异常 : Column "Salman" not found;

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:03:43 24 4
gpt4 key购买 nike

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

@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));

}
}

customerTest.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")

同时“Salman”是一个值而不是一列?

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

最佳答案

编译器产生这种错误的行为对我来说仍然是一个问题,但我设法使用这个单引号 '' 而不是双引号 ""

来处理这个错误

我用这个

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

而不是

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

关于java - org.h2.jdbc.JdbcSQL异常 : Column "Salman" not found;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35646432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com