File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Run .sql file using JDBC or any java API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Run .sql file using JDBC or any java API" Watch "Run .sql file using JDBC or any java API" New topic
Author

Run .sql file using JDBC or any java API

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
Hi ranchers,

This is Venkat. I am currently developing a installer. This intaller has a task of running initial database scripts (.sql file) on a database server.

Is there any way that i can run .sql file using JDBC or hibernate or any other API's.

The intital scripts include,

1) user creation script.
2) create tables for above created user.


Please help me as soon as possible.

Thanks in advance,
Venkat
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Java has an IO API you can use to access the file - see the java.io package. Once you have the contents of the file its easy to run them via JDBC or Hibernate.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
You can read the file one sql statement at the time and execute it through the JDBC.

for oracle the single line sqls like select, inser etc are terminated by ';'
and PL SQL blocks by '/' so you can use these separators to distinguish the sql sattements
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Run .sql file using JDBC or any java API