File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help: Why can't jdbcTemplate get this record?

 
pengpeng lin
Greenhorn
Posts: 26
  • 0
  • 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>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic