This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help: Why can't jdbcTemplate get this record?

 
pengpeng lin
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic