• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

can i execute sql script directly by java?

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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~
 
author & internet detective
Posts: 42055
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anil,
can you start a new topic?
This one is 2 years old.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to start a new topic; it already exists: executing an sql through java
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic