2

I have to call .sql file from java program.

SQL file has some account numbers and below is a select query written. The select query should be executed for all the account numbers present above the select query.

Please provide me if there is any sample code for the above requirement.Is that possible?
Thanks In Advance.

Anthony
  • 12,407
  • 12
  • 64
  • 88
satish
  • 287
  • 6
  • 22
  • Possible duplicate of [How to execute sql-script file in java?](http://stackoverflow.com/questions/2071682) – Roman C Sep 27 '12 at 12:54
  • possible duplicate of [How to execute sql-script file in java?](http://stackoverflow.com/questions/2071682/how-to-execute-sql-script-file-in-java) – Leigh Dec 10 '12 at 05:22

2 Answers2

2

There is no standard framework to do this; you will have to use Java IO to read the file, parse the content and then use JDBC to execute the SQL query.

Since JDBC is a bit strange/boring to use at times, you may want to look at a framework which makes your life easier. I suggest jOOQ.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Thanks Aaron.Actually my requirement is I will create connection to DB in java and call the script file.Now script file should be executed i.e control go to script code normal script execution.Finally after executing for all account numbers control should come to java file Is That possible? – satish Sep 27 '12 at 13:23
1

SQL files are not "callable". If you have a database connection you can execute it this way on the database.

So your java application have to connect to a database and then execute the SQL script. You should read something about JDBC connections, here is a tutorial: http://docs.oracle.com/javase/tutorial/jdbc/TOC.html

Kai
  • 38,985
  • 14
  • 88
  • 103
  • Thanks.Actually my requirement is I will create connection to DB in java and call the script file.Now script file should be executed i.e control go to script code normal script execution.Finally after executing for all account numbers control should come to java file Is That possible? – satish Sep 27 '12 at 13:29