aspose file tools
The moose likes JDBC and the fly likes Load and execute SQL from multiple line file? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Load and execute SQL from multiple line file?" Watch "Load and execute SQL from multiple line file?" New topic
Author

Load and execute SQL from multiple line file?

Mark Hissink Muller
Greenhorn

Joined: Sep 15, 2003
Posts: 4
Kindly I would like to ask what is the preferred way of loading a file containing multiple sql-statements (CREATEs and INSERTs) into a (MySQL) database?

In the setUp()-method of a JUnit-test, I would like to freshen up the test-database by dropping all tables and loading a new default state. Since some of the INSERT-statements contain quotes (") or other special characters, I cannot just load everything into a single Statement.

Is there a convenient way to encode the data so it can be used in a simple statement.executeQuery(sql)?

Thanks for your time,
Mark
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26141
    
  66

Mark,
You could parse the file (by statement termination character) and executeUpdate() for each statement. Alternatively, you could do a batch update and save on trips to the database.


[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
Mark Hissink Muller
Greenhorn

Joined: Sep 15, 2003
Posts: 4
Thanks for your thoughs Jeanne. I solved it like this:

 
I agree. Here's the link: jrebel
 
subject: Load and execute SQL from multiple line file?
 
Similar Threads
Best and optimum method to delete the first line from pipe delimited file with HUGE size
Back Up & Restore Database
Multiple Updates
Setting up test data in Junit
Sending a list of SQL Statements to the Server (out of the java program)