my dog learned polymorphism*
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
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Help: Why can Watch "Help: Why can New topic

Help: Why can't jdbcTemplate get this record?

pengpeng lin

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 {
String sql = "Select USERNAME from NEWSLETTER_USER where UPPER(USERNAME)= ?";
String userName = (String) jdbcTemplate.queryForObject(sql,
new Object[] { "PAUL" }, java.lang.String.class);
assertEquals(userName, newUser.getUserName());
} catch (NewsletterException ne) {

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:
subject: Help: Why can't jdbcTemplate get this record?
Similar Threads;)Ljava/la
Partioning with String based key
need help with basic spring mvc program... please help
Spring - MySql Connectivity Error
Get object failed with jdbcTemplate when using Spring to test