This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help: Why can't jdbcTemplate get this record?

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 {
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'm full of tinier men! And a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic