• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a database from Java Source Code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay,
the filed solution obviously does not work.
Still the question remains how to solve such a problem. Not from source code??
Regards
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic