0

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.

my JUnit test method is as below:

    @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.

Thank you

fredt
  • 24,044
  • 3
  • 40
  • 61
Chitresh
  • 3,022
  • 12
  • 35
  • 40

1 Answers1

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

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.

fredt
  • 24,044
  • 3
  • 40
  • 61
  • i have give a size varchar(40) which can hold a value of UUID. i generated my primary key with java UUID.random().toString() function. i don't think it is a issue of size. because as i has told in my question that the same method when i debug with same value it's giving me a exception integrity violation exception. and after the exception when i run my get method for the same record it's return me a value. so any other suggestion – Chitresh Mar 09 '11 at 12:19
  • thanks fredt it works. right now i set this property with help of hsqldb databasemanagerswing tool. but can you tell me how can i set the same property in spring-config.xml – Chitresh Mar 10 '11 at 05:00