Announcement Announcement Module
No announcement yet.
Spring JDBC & dynamic sql Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JDBC & dynamic sql

    Hi, just wated find out what would be the best way to use spring jdbc classes for dynamic searches. The sql is not known at the program's start, the number of parameters are changing. Should I compile the sql on every execution? Is there a way to cache compiled statements for repeating input parameters?

  • #2
    Use JdbcTemplate, not the JDBC object approach. This enables you to set the SQL just before you query, but still use PreparedStatements.

    Of course if you are issuing lots and lots of different SQL statements, your design may be problematic (nothing to do with Spring): the database won't be able to keep all your queries cached, and will need to do a lot of work each time. Do you keep seeing particular combinations of parameters being reused, in which case performance should be OK?


    • #3
      Just wanted to add that most connection pools suppport a prepared statement cache. This might help if you have repeated use of the same statement. Spring itself does not provide this type of caching.