*
The moose likes Other Application Frameworks and the fly likes Help: Why can't  jdbcTemplate get this record? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Help: Why can Watch "Help: Why can New topic
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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help: Why can't jdbcTemplate get this record?