aspose file tools*
The moose likes JDBC and the fly likes Creating a database from Java Source Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Creating a database from Java Source Code" Watch "Creating a database from Java Source Code" New topic
Author

Creating a database from Java Source Code

Walther Mueller
Greenhorn

Joined: Jan 16, 2009
Posts: 3
Hello,
I'm trying to develop a local database using derby/JavaDB.

I've created a txt-file where I have the DDL-Statements to create the database and
a txt-file where i initialize the tables with INSERT statements.

I think I've found a solution how to load these txt files from Java and execute them here on the board.

Execute file


My question is, what ist the best practise on to perform the file only once?

I've seen solutions were this is done in the built.xml but I'don't know exactly how to do it.
My naive solution would be to put a counter in the main method were my application is started and to change the
counter the first time the application is started and the database created.
I would check the counter with a if-clause to ensure the txt-files aren't executed twice.

Any others/betters ideas?
Cheers Walther
Walther Mueller
Greenhorn

Joined: Jan 16, 2009
Posts: 3
Okay,
the filed solution obviously does not work.
Still the question remains how to solve such a problem. Not from source code??
Regards
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29261
    
140

Can you do a database query to see if a table created by the DDL exists? That would tell you if it had been run already.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a database from Java Source Code
 
Similar Threads
Reading file from client machine
Summary of Struts, by Struts newbie
BMP, Jboss, and mysql configuring
file type association with my java program
where is my webapp?