wood burning stoves 2.0*
The moose likes JDBC and the fly likes executing .sql file from java program 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 "executing .sql file from java program" Watch "executing .sql file from java program" New topic

executing .sql file from java program

S Srikanth

Joined: Sep 09, 2002
Posts: 14
I have a .sql file which consists of some DDL Commands.
I need code snippet to execute the .sql file from java?

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

you can not execute a sql file straight to your database from jdbc.


Please look at JavaRanch Naming Policy and change you display name.As per policy a display name is first name and last name saperated by a space. you can do the same here


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
S Srikanth

Joined: Sep 09, 2002
Posts: 14
Is there any alternative to this?

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

You can:
  • Read the file in with java.io
  • Parse its contents - you'll probably need java.util.regex for that
  • Create a batch of Statements to execute via JDBC.

  • Sounds like a lot of work. Given this is DDL rather than DML, can't you just execute it via whatever DB client you would normally use. Far easier.

    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    David O'Meara

    Joined: Mar 06, 2001
    Posts: 13459

    thank you for changing your diaply name, but unfortunately we need: your first name, a space, then your last name.

    Please edit your profile and correct your display name.

    I agree. Here's the link: http://aspose.com/file-tools
    subject: executing .sql file from java program
    Similar Threads
    how to use .sql files using java
    create tables using java code by fetching from .sql file
    DB Backup - MySql
    Struts sql query grouping
    Export into file, sql query to insert data