Announcement Announcement Module
No announcement yet.
How to pass null to SqlUpdate.update Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to pass null to SqlUpdate.update

    Hi all,

    I'm new to Spring, but as far as it goes, I like it.

    I have a couple question here, hope you can help me out.

    1. I tried to update a row in database using SqlUpdate.update(object[]) method. Since some of the field in the row may not be set, sometimes some field in input array will be null.
    When I execute the code I got exception saying "Driver not capable". I figure out that it only happen when any of the parameter i passed to update([]) method was null.
    The field that was null does not have NOT NULL constrain in DB. And it works If I modified the sql and put "null" in the sql string where the value should have been.

    I know that if I set the PreparedStatement directly I can use its setNull() method. However, that seems like a hack to me. Another place I look is PreparedStatementSetter but i don't think that's the right way.

    I use JdbcOdbc pooled with DBCP with FireBird DB.

    2. Currently, When I want to do query, I subclass all my query from MAppingSqlQuery. And When I want to do Update, Insert or Delete, I subclass then from SqlUpdate.
    Is this what I should be doing. Or is it any better pattern you would use. Many people in here seems to use JDbcTemplate Directly.


  • #2
    1. From what you describe, it sounds like it is a driver problem. I'm not sure why you are using JdbcOdbc driver. Doesn't FireBird have a JdbcDriver? Could you post some code and a debug log?

    2. Both approaches are valid and I tend to subclass MappingSqlQuery for more complex queries and use JdbcTemplate for simpler stuff.


    • #3
      Yes, It is indeed a driver problem. I switched to use Jaybird Jdbc and it works fine.

      A little on going question here.
      For all those SQLupdate or JDbcTemplate, does it automatically do rollback in case of Exception?