Take the 2-minute tour ×

I am writing an application that I want to store, retrieve, sort, and search data. I am using Java and I have the GUI and some functionality written already but I have no idea how to store data in Java. I have done a VERY little bit of work with SQLite when I was writing an app for my android phone and was looking for something like that maybe.

I need to store information that is linked to each other, for example think of an address book. The name, address, phone number, email address, etc. would be linked to each other and go together for one entry in the address book. Similarly I need to store a large amount of data in this way and be able to search it for needed data. I would also like to be able to retrieve the data in a fashion that I could get the address value for "name".

I need to know the easiest way to accomplish this. After googleing it I found information on Java DB but I don't know if this is exactly what I am looking for or how to use it.

Please answer by providing me with information on what to use to store the data and if possible point me in the direction of a tutorial on how to use it.

Thank you.


I appreciate the Help but I am still not getting it. I want to use SQLite and I followed the link that Kristian Antonsen gave and I downloaded the SQLiteJDBC thing but now I am lost. I am clearly in new territory here and completely lost.

Can someone give me an "idiots guide" on how to use this and make it work in my application?

Thanks again.

share|improve this question
I admire your persistence in teaching yourself this stuff. –  DOK Jan 5 '12 at 23:14
Thank you. I am doing what I can –  Dead_Jester Jan 5 '12 at 23:36
@Dead_Jester it seems that you should start at stackoverflow.com/questions/41233/java-and-sqlite — they list several options which could be of help to you. The wiki page they refer to, ci.uchicago.edu/wiki/bin/view/VDS/VDSDevelopment/UsingSQLite, seems to be moved now. If it won't work, let me know, I'll find it again :) –  alf Jan 6 '12 at 10:01
add comment

5 Answers

There are lots of ways to accomplish this, here's a few

share|improve this answer
Ok, so I can use SQLite, good. Now the link you posted gives another Stack Overflow Question with multiple answers. Which answer do you reccomend? The one talking about David Crawshaw or the one talking about wiki? –  Dead_Jester Jan 5 '12 at 23:29
@Dead_Jester The link now points to Bernie Perez's answer - that's the one with an actual implementation example. How familiar are you with SQL? –  kba Jan 6 '12 at 8:23
@Dead_Jester What is your problem? Where are you stuck? I just downloaded the example program I linked and used this SQLite JDBC driver and tested it. The example works flawlessly. –  kba Jan 6 '12 at 14:15
add comment

A very simple and easy to use database you can use is db4o. The good thing about db4o is that you can store plain old Java objects in your database! No need to map them to tables and back!

Alternatively, if you like to use the SQL language (similar to SQLite), you can use H2DB. JavaDB, is also another option. Both of H2DB and JavaDB can be used as embedded databases and distributed with your app.

If you decide to use SQL, you need to learn JDBC (Java Database Connectivity). It lets you communicate with the SQL database of your choice. If JDBC seemed too level for your taste, then you can learn JPA (Java Persistence API).

However, IMHO, unless proven otherwise, db4o seems the best option for your use case and situation in my opinion.

share|improve this answer
add comment

I would like to support Kristian Antonsen on his comment because HashMaps are the best method to store data in Java. If you want to store data in alphabetic order, TreeMap is the more convenient way.

share|improve this answer
Jdbc(Java DataBase Connectivity) is also a useful & important concept when u need to connect with the database –  sonu Jan 5 '12 at 23:23
add comment

Aside from what Kristian Antonsen already mentioned, I should also mention Hibernate. I just recently picked it up by going through a series of YouTube videos such as this playlist

From what I gathered, it is a better solution that's built on top of JDBC (which can be tedious).

I would suggest you make the decision based on what your project needs and the time you have.

share|improve this answer
add comment

In order to use SQLite, try following this discussion: Java and SQLite

The old version (I believe it still holds):

The Easiest Way: serialize your data object on exit, de-serialize it on startup. For a sample application, prototype, or a quick test it works wonders, and does not require much coding.

For downvoters: yes I do use this approach every time I need to start with something. I don't need to worry much about details, and I know I can change my persistence layer later on. It does help to postpone important storage decisions until I know what kind of data I have.

Less easy way would involve a database, but that requires a proper data design—if you don't share it, it's hard to recommend anything specific. The reasonable choices could be SQLite, mySQL, MongoDB or almost any other database. What fits better in your case is hard to say.

share|improve this answer
to downvoter: care to explain? –  alf Jan 5 '12 at 23:17
I'm not the downvoter, but alf, where are you putting the serialized data? In a file, in a database, in server memory, or what? –  DOK Jan 5 '12 at 23:20
@DOK a file of course. By the time you need more than one node (and have the real problem, which may as well render embedded databases as SQLite useless), you usually have enough experience so that you are not asking such questions. –  alf Jan 5 '12 at 23:23
So your answer is not for newbe's because you assume the user knows how to serialize data to file, and not for experienced users because they would know about serialization anyway. That seems to be a reason to downvote in my book (no, I didn't do it either, no viciousness from me in this case). –  owlstead Jan 6 '12 at 3:28
@owlstead when I was learning Java, JDBC was considered less newbie technique than serialization... So YMMV. Anyway, got the point, thank you. –  alf Jan 6 '12 at 10:03
add comment

Your Answer


