rocket mass heater kickstarter
The moose likes JDBC and Relational Databases and the fly likes running sql script file from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "running sql script file from java" Watch "running sql script file from java" New topic
Author

running sql script file from java

Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
Hi Guys,
Can a sql script file be run from the java application?
Please share.
Regards,


Sanjeev Kaushik
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31585
    
185

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().


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sanjeev Kaushik
Ranch Hand

Joined: Aug 01, 2002
Posts: 105
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

Joined: May 26, 2003
Posts: 31585
    
185

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

Joined: Sep 28, 2001
Posts: 925
well you can send anonymous pl/sql in jdbc. have you tried opening the file and sending the contents as a callablestatement?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running sql script file from java