Announcement Announcement Module
Collapse
No announcement yet.
best practice for insert queries Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • best practice for insert queries

    hello,
    just wanted to see what other spring developers use for insert queries. I know there is MappingSqlQuery for mapping to objects, and UpdateQuery for update queries.

    I was thinking about using the JDBCTemplate object, but just wanted to see what you guys use as alternatives..

    thx!

    ec.

  • #2
    Updates and inserts can be handled the same way.

    Comment


    • #3
      I use the JdbcTemplate methods for update and insert just like below:

      for an update
      try
      {
      getJdbcTemplate().update(sqlQuery.toString());
      }
      catch(DataAccessException e)
      {
      log.error(e.getMessage());
      }

      for an insert
      try
      {
      getJdbcTemplate().execute(sqlQuery.toString());
      }
      catch(DataAccessException e)
      {
      log.error(e.getMessage());
      }


      I use the update method to perform an update because it return the affected row number. But the execute should work for the two tasks.

      The JdbcTemplate provides lots of useful methods.

      Comment

      Working...
      X