hsqldb在使用JUnit测试运行时未显示插入查询的反射

时间:2021-12-23 15:41:53

i am using hsqldb as database. i create LmexPostParamDao which has a method insertLmexPostParam(NameValuePostParamVO nameValuePostParamVO) which will insert data in databse. for testing this method i used JUnit test to insert some data in hsqldb.

我使用hsqldb作为数据库。我创建了LmexPostParamDao,它有一个方法insertLmexPostParam(NameValuePostParamVO nameValuePostParamVO),它将在数据库中插入数据。为了测试这个方法,我使用JUnit测试在hsqldb中插入一些数据。

my JUnit test method is as below:

我的JUnit测试方法如下:

    @Test
public void testInsertLmexPostParam(){
    String lmexPostParamId = UUID.randomUUID().toString();
    NameValuePostParamVO nameValuePostParamVO = new NameValuePostParamVO();
    nameValuePostParamVO.setLmexPostParamId(lmexPostParamId);
    nameValuePostParamVO.setParamName("adapter_id");
    nameValuePostParamVO.setParamValue("7");

    lmexPostParamDao.insertLmexPostParam(nameValuePostParamVO);
}

my insert method is as below:

我的插入方法如下:

    @Override
public void insertLmexPostParam(NameValuePostParamVO nameValuePostParamVO) {
    String insertQuery = "insert into LMEX_POST_PARAM(lmex_post_param_id, param_name, param_value) values (?,?,?)";
    String[] paramArr = { nameValuePostParamVO.getLmexPostParamId(), nameValuePostParamVO.getParamName(), nameValuePostParamVO.getParamValue()};
    int update = adapterJdbcTemplate.update(insertQuery, paramArr);
    System.out.println(update);
}

when i run my test case it's returning me 1 as output which is result of adapterJdbcTemplate. which means data inserted sucessfully. but when i see my database it is not showing me a that row which inserted. and when i debug my testcase method with same values it's give a exception : Data integrity violation exception. and after this exception when i see my database it's showing that row in my database. what will be the problem. i do not. when i see code it's look like everything is fine. help me to resolve this.

当我运行我的测试用例时,它返回1作为输出,这是adapterJdbcTemplate的结果。这意味着数据插入成功。但当我看到我的数据库时,它没有显示我插入的那一行。当我用相同的值调试我的testcase方法时,它会给出一个异常:数据完整性违规异常。当我看到我的数据库时,它会在我的数据库中显示该行。会是什么问题。我不。当我看到代码时,看起来一切都很好。帮我解决这个问题。

Thank you

谢谢

1 个解决方案

#1


0  

Check your CREATE TABLE statement for LMEX_POST_PARAM. The CHAR and VARCHAR types must be defined as CHAR(N) and VARCHAR(N), with N large enough to accept the values that you insert. For example, VARCHAR(100).

检查您的CREATE TABLE语句以获取LMEX_POST_PARAM。 CHAR和VARCHAR类型必须定义为CHAR(N)和VARCHAR(N),其中N大到足以接受您插入的值。例如,VARCHAR(100)。

If your problem is the database is not showing the successful insert, then you should create your database with WRITE_DELAY = 0 or false. See the HSQLDB documentation for the version you are using.

如果您的问题是数据库未显示成功插入,那么您应该使用WRITE_DELAY = 0或false创建数据库。有关您使用的版本,请参阅HSQLDB文档。

#1


0  

Check your CREATE TABLE statement for LMEX_POST_PARAM. The CHAR and VARCHAR types must be defined as CHAR(N) and VARCHAR(N), with N large enough to accept the values that you insert. For example, VARCHAR(100).

检查您的CREATE TABLE语句以获取LMEX_POST_PARAM。 CHAR和VARCHAR类型必须定义为CHAR(N)和VARCHAR(N),其中N大到足以接受您插入的值。例如,VARCHAR(100)。

If your problem is the database is not showing the successful insert, then you should create your database with WRITE_DELAY = 0 or false. See the HSQLDB documentation for the version you are using.

如果您的问题是数据库未显示成功插入,那么您应该使用WRITE_DELAY = 0或false创建数据库。有关您使用的版本,请参阅HSQLDB文档。