| Author |
Help: Why can't jdbcTemplate get this record?
|
pengpeng lin
Greenhorn
Joined: Dec 24, 2005
Posts: 26
|
|
I use spring class AbstractTransactionalDataSourceSpringContextTests to test my service logic, below is my testing code: ========================================================== public void testSaveUser() { User newUser = createUser(); try { userService.saveUser(newUser); assertTrue(true); <b>setComplete();</b> String sql = "Select USERNAME from NEWSLETTER_USER where UPPER(USERNAME)= ?"; String userName = (String) jdbcTemplate.queryForObject(sql, new Object[] { "PAUL" }, java.lang.String.class); assertNotNull(userName); assertEquals(userName, newUser.getUserName()); } catch (NewsletterException ne) { fail(ne.getMessage()); } } please note that the setComplete() call, I found that the save operation has succeed to insert a record to databae, and the sql: <b>Select USERNAME from NEWSLETTER_USER where UPPER(USERNAME)= 'PAUL'</b> can get the expected result while running in SQL*PLUS. But when test run it failed at <b>assertNotNull(userName)</b>, the error message said that the jdbcTemplate.queryForObject method return a <b>null</b> object. <b>So why can't the jdbcTemplate get the record even if transaction has been committed?</b>
|
 |
 |
|
|
subject: Help: Why can't jdbcTemplate get this record?
|
|
|