I`m creating a desktop application which need s to store some data. I would probably store no more than 100rows with 10-15cells. Question is, should I use csv or an sql database; which one is accessed faster ?

It depends on how you need to access the data, but I would imagine the simple file would suffice. You don't mention what the data is, but basically you have the equivalent of a single table. With file-based storage you will need to write the methods yourself if you want to query the data in any manner. If such queries are straightforward, such as just finding a couple entries based on simple criteria, you really don't need the database.

That said, if you expect to grow to have several other tables of information and will need to correlate information between them in a variety of ways, you should go ahead and start with a database.

McKoi and H2 are a couple of good open-source Java embedded databases (they don't need a separate installation on a server) if you decide you want to use the database.

That's a good question. For this small amount of data you can work with cvs or xml files. Setting up the database and making it work in your code will take longer that doing so for the text files.

However, parsing files is easy but it is slow, so if, in cases like this, there's even the slightest possibility of expansion, you might want to use the database. If you have the time, you'll be able to learn all about persistence in programming which is really a big concern these days. As a developer you'll encounter persistence problems a lot, so starting to work with it the good way would be a good idea.

It depends on the time you are able to spend on it.

When you do choose to go for the database, you might want to look into Hibernate, it provides easy data persistence using object/relational mapping. They have good tutorials that will have you run basic persistence in no time. Seeing you would be able to manage with cvs files, a database scheme cannot be complicated. Therefor your Hibernate configuration won't be too.

You can find Hibernate here: link.
And an introductional tutorial (that should allready get your little project off the ground) here: read chapter one.

If you have any more questions about this, feel free to ask them.

Why am I over-enthousiastic? I'm a fan of Hibernate and a believer of the ORM solution. :)

Black Box

It depends on how you need to access the data, but I would imagine the simple file would suffice. You don't mention what the data is, but basically you have the equivalent of a single table. With file-based storage you will need to write the methods yourself if you want to query the data in any manner. If such queries are straightforward, such as just finding a couple entries based on simple criteria, you really don't need the database.

That said, if you expect to grow to have several other tables of information and will need to correlate information between them in a variety of ways, you should go ahead and start with a database.

McKoi and H2 are a couple of good open-source Java embedded databases (they don't need a separate installation on a server) if you decide you want to use the database.

The data will contain strings, numbers, dates, images!!!(I don`t have a clue where and how to store this ones(.jpg)). Practically, I`ll be using the data when: I execute the program and my saved data will be displayed in a JTable; I`ll add new data; I want to have the possibility to make sort on most of the columns; Maybe I`ll make a search box... .

I don`t think I`ll need more than 1 table(hope not).

and last thing, it is possible to have more than 100 records, but that depends on how my program will behave when I`ll do some queries on 1-2-300 records database/csv. I really want to obtain a fast and relatively light program.

For those images, you can store the path to it.

For those images, you can store the path to it.

Agreed. I'd recommend that even with a database.


...

When you do choose to go for the database, you might want to look into Hibernate, it provides easy data persistence using object/relational mapping. They have good tutorials that will have you run basic persistence in no time. Seeing you would be able to manage with cvs files, a database scheme cannot be complicated. Therefor your Hibernate configuration won't be too.

...

Black Box

I`m sorry because i haven`t tried those links yet but, does Hibernate works like those 2 examples given by Ezzaral, McKoi and H2, and embedded database seems to be a very good idea , cause I`m not forced to install MySql or another RDBMS

Well, the only thing you'd have to do is follow the guide really. It will take you little time to setup everything you need (including the link of the database to your program).

You can use about every database with Hibernate, though the tutorial uses HSQL DB. Downloading & installation (about a minute or two of work) is explained in the tutorial. If you have specific questions about that, I've been through it myself (including that one tutorial), ask away.

Black Box

Hibernate will work with H2 and McKoi as well, so you can still use an embedded database without a server installation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.