aspose file tools*
The moose likes JDBC and the fly likes can i execute sql script directly by java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "can i execute sql script directly by java?" Watch "can i execute sql script directly by java?" New topic
Author

can i execute sql script directly by java?

Sylven Yip
Ranch Hand

Joined: Aug 30, 2007
Posts: 42
hi everyone.
now I have a sql script file generate by MySQL.
is it necessary to read the sql script file(*.sql) by I/O and analyse by my program and then execute them?
thanks for help~
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Sylven,
No. You can use Runtime.exec and have it run the sql script at a command line. This is the same as using your database's command line tool to run a script.


[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
Mladen Grabowsky
Greenhorn

Joined: Sep 19, 2007
Posts: 29
You could use iBatis' ScriptRunner, it was made for that purpose: http://ibatis.apache.org/docs/java/user/com/ibatis/common/jdbc/ScriptRunner.html
Sylven Yip
Ranch Hand

Joined: Aug 30, 2007
Posts: 42
thanks!
Anil Bansal
Greenhorn

Joined: Jun 18, 2009
Posts: 4

Hi All,
I also wanted to execute an sql script through java but had one more requirement. I wanted to ensure that the password that i am using to connect to the database as well as the arguments to the script are not visible through ps commands.
Can you suggest me a way in which i can redirect the password as well as the arguments through a file using java.
something like:
runtime.exec(sqlplus system@db @some.sql <tmp)
where tmp is the temporary file and has the password to connect to the db as well as the arguments required by the sql file.
This is not working in java through runtime command but the same kind of thing works in a shell script.

Is there any other better way of achieving the same.

Thanks,
Anil
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2499
    
    8

Hi Anil,
can you start a new topic?
This one is 2 years old.


OCUP UML fundamental and ITIL foundation
youtube channel
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41800
    
  62
No need to start a new topic; it already exists: executing an sql through java


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can i execute sql script directly by java?