This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running sql script file from java

 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
Can a sql script file be run from the java application?
Please share.
Regards,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not in JDBC. If your database happens to be running on the same machine as the Java application, you can run the script using Runtime.exec().
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No sql script does not run on command prompt. We can run this in sql editor or some sql tool like Toad.
syntax is like this
@myscript
Where myscript.sql is a file which contains some sqls.
Like we can execute sql queries and stored procedures from Java, can we run these scripts file also.
I think my question would be more clear now.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database are you using? Many database provide a way to run scripts (list of SQL commands) from the command line. I know it is possible in Oracle, db2 and mySql.
I stand by what I said before: you cannot run the script through JDBC.
 
SJ Adnams
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well you can send anonymous pl/sql in jdbc. have you tried opening the file and sending the contents as a callablestatement?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic