*
The moose likes JDBC 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30124
    
150

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


[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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30124
    
150

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
 
Similar Threads
Executing shell script from java
Running sql scripts
Setting classpath when using Runtime.exec()
how to execute .sql file using java
How to send a J2EE web application linked to mysql database to others?