Results 1 to 6 of 6
  1. #1
    _SAS is offline Member
    Join Date
    Jan 2010
    Location
    Russia
    Posts
    9
    Rep Power
    0

    Default A way to execute multiple queries from an SQL script file?

    Hello.
    I've got a SQL file with multiple queries in it. Is there any way to execute them all? Maybe there is a library which can do that?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default Re: A way to execute multiple queries from an SQL script file?

    Quote Originally Posted by _SAS View Post
    Hello.
    I've got a SQL file with multiple queries in it. Is there any way to execute them all? Maybe there is a library which can do that?
    Read the file and pass them all through a Statement/PreparedStatement

  3. #3
    _SAS is offline Member
    Join Date
    Jan 2010
    Location
    Russia
    Posts
    9
    Rep Power
    0

    Default Re: A way to execute multiple queries from an SQL script file?

    As far as I know, you cannot put multiple queries into one Statement. I could execute them one by one, but in order to do so I have to parse my SQL file. But it is too complex a task since my file contains creation of pl/sql functions. I simply don't know how to break it into individual queries without writing a complex SQL parser.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: A way to execute multiple queries from an SQL script file?

    Why not simply hand the sql file to the database directly?
    Most DBs have a front end for doing bulk SQL.
    Please do not ask for code as refusal often offends.

  5. #5
    _SAS is offline Member
    Join Date
    Jan 2010
    Location
    Russia
    Posts
    9
    Rep Power
    0

    Default Re: A way to execute multiple queries from an SQL script file?

    For some unknown reason I can't communicate with psql process. I start the process, and nothing happens. I can't read its output and I can't pass the data to it. So I thought that using some library would be the right way to do the thing.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: A way to execute multiple queries from an SQL script file?

    This sort of thing is almost invariably better done using whatever tools the DB provides you with.
    Not knowing your database I can't say what tool, but if you need to call it via Java then you'll want to use Runtime.exec(), but beware of the pitfalls and ensure you read up on how it works.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Execute sql script from java
    By nikosdi in forum JDBC
    Replies: 0
    Last Post: 06-10-2011, 01:52 PM
  2. Multiple queries - is it smart to enable this
    By flyfisherman in forum JDBC
    Replies: 8
    Last Post: 04-23-2010, 06:13 PM
  3. jar file won't execute.
    By Splat in forum New To Java
    Replies: 5
    Last Post: 10-22-2009, 05:26 AM
  4. Multiple Queries using batch Updates
    By swati.jyoti in forum JDBC
    Replies: 3
    Last Post: 05-12-2009, 10:40 AM
  5. Replies: 0
    Last Post: 07-11-2007, 01:22 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
  •