aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executing .sql file from java program" Watch "executing .sql file from java program" New topic
Author

executing .sql file from java program

S Srikanth
Greenhorn

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

Regds,
Srikanth
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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


"sreek_s@yahoo.com"

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


Shailesh


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

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

Regds,
Srikanth
Paul Sturrock
Bartender

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
    Rancher

    Joined: Mar 06, 2001
    Posts: 13459

    "Srikanth",
    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.

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