Results 1 to 4 of 4

Thread: Running SQL scripts through JdbcTemplate

  1. #1

    Default Running SQL scripts through JdbcTemplate

    Hi,

    I'm working on a program to incrementally upgrade our application's database schema. Our app already uses Spring, so what I'd really like to do is use JdbcTemplate to execute DDL script fragments stored as class path resources (i.e. multiple DDL statements in a single string).

    Is this feasible? What JdbcTemplate call should I be using? I tried using execute(String), but Oracle barfs with an "invalid character" error when it encounters the semi-colon used to separate statements.

    Any ideas?

  2. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    You may need to break up the statements by parsing for the semi-colon yourself.

    You might consider using the BatchSqlUpdate object to execute all statements in one call.

  3. #3

    Default

    Yes, after much Googling, I've come to the same conclusion. I can't believe no one has written a little Java API to do this. This would be a very nice enhancement to JdbcTemplate! Hmmm...

    Someone on one of the Sun forums pointed out that Ant has a built-in SQL task. The source code for that might be adaptable. Haven't looked into it yet.

  4. #4

    Default

    Well, if anyone's interested, I've created a simple script parser and submitted the code through JIRA (SPR-1197). It's loosely based on the SQL task in Ant, but with some changes. This one will ignore comment delimiters in string literals, for example.

    Enjoy.

Similar Threads

  1. Replies: 5
    Last Post: Oct 1st, 2010, 08:00 AM
  2. Replies: 3
    Last Post: Sep 23rd, 2009, 10:26 AM
  3. Replies: 1
    Last Post: Oct 13th, 2005, 06:38 PM
  4. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  5. Transaction Management
    By caverns in forum Data
    Replies: 3
    Last Post: Mar 8th, 2005, 06:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •