4

I have a Java SE application, and it uses a database. I am currently using XML files to store data, but I´m afraid it causes some errors in later use.

So it would be good to use a Postgree/MySQL like DB. A real database. but the problem is, it is a commercial application, it runs under windows, and should be 2 clicks to install. I really don't like the idea of installing a database together with my application, and then running scripts to build the tables.

Is there a database that I can use as a Java API? Or should I just continue to use XML? (I'm synchronizing every access to my XML files). Whats the best choice?

mauris
  • 42,982
  • 15
  • 99
  • 131
fredcrs
  • 3,558
  • 7
  • 33
  • 55
  • 2
    possible duplicate of [Embedded java databases](http://stackoverflow.com/questions/57102/embedded-java-databases) – Valentin Rocher Dec 13 '10 at 13:42
  • Check this usage example, http://debuggingisfun.blogspot.com/2012/05/quick-and-easy-setup-of-database-in.html – ethan May 18 '12 at 21:00

4 Answers4

13

One of following embedded databases:

They are lightweight, take up very little space and can be embedded without problems in your application.

Since they are written in Java, and each one is a simple jar file, your deployment headaches will be kept to a minimum.

You've mentioned MySQL and PostgreSQL. Although I haven't tried it, H2 features several compatibility modes for various popular databases, including ones you've mentioned.

darioo
  • 46,442
  • 10
  • 75
  • 103
  • Derby is illustrated in http://debuggingisfun.blogspot.com/2012/05/quick-and-easy-setup-of-database-in.html – ethan May 18 '12 at 21:01
4

H2 Database

It can be embedded in your application with no clicks to install and it supports JDBC and most ORMs.

willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111
3

It is definitely worth to look for a simple SQLite database as the storage. It is just a single file on your file system. No need to set up a server. Check out the following thread for an introduction: Java and SQLite Another database you could check out is HSQLDB (link inside another answer inside this thread). That one is a relational database engine written in Java also based on a single file.

Community
  • 1
  • 1
Christian Stade-Schuldt
  • 4,671
  • 7
  • 35
  • 30
1

Based on my previous naive experience of storing data into XML, I wrote a entire forum system on XML and it's based on RSS parser and writer. The XML files became very big and thus causing frequent request time outs on the application.

You can instead use something like SQLite, where data is stored in a file but more managed and allows declarative statements like SELECT * FROM table.

mauris
  • 42,982
  • 15
  • 99
  • 131