开发者

Databases for java applications

开发者 https://www.devze.com 2023-02-23 02:41 出处:网络
I would like to get your advice. I\'m building an application thats going to store artist info, music and other stuff. I was going to use XML as a type of database, but when I was reading some posts o

I would like to get your advice. I'm building an application thats going to store artist info, music and other stuff. I was going to use XML as a type of database, but when I was reading some posts on this site, some people said to use a java database. Now I didnt know that they existed for standalone apps. So I came across SQL lite and objectdb. Am I correct to assume that if I was to u开发者_如何学JAVAse either of these, that the user would have to install separate software? Or will the database software get integrated/compiled/bundled/packaged with my application? I was reading about objectdb and it looks like its something that will get packaged with my application, but not sure. Still learning java more so I apologize for my noob questions.

I would like to get your advice and opinions about this please, thanks!


SQLite is a great choice for exactly what you're referring to - a standalone desktop application. It's overhead is minimal, it does not require a running DBMS and therefore does not introduce a dependency at installation time. In actual fact it's incredibly lightweight, all tables are stored within a single .db file. This obviously introduces potential problems with scalability for your application I can't see this becoming a problem.

To get started you will need a driver/wrapper for the SQLite API (it's a C API so a wrapper will prevent you form having to write JNI code!). SQLiteJDBC is one such wrapper...

  • SQLiteJDCB

You might also want to get familiar with the SQLite runtime. It provides a console application to manage tables/schemas. Here's a good starting tutorial...

  • SQLite Command Line Tutorial


Don't use XML for storing your database, unless it will fit completely into the heap memory. XML is designed for exchanging data, not for storing it. For example, you cannot say "get me track 7 of that album" without loading the complete XML file. Typical databases can do that.


Maybe you should have a look at the H2 Database Engine. It is very easy to embed into Java because its only a small (~ 1MB) jar-File. I did not used it by myself but recommended it to many friends and they all gave me a good feedback.

Here you can find a nice tutorial.


If you are writing a desktop application in java using a simple SQL database such as SQLLite or HSQLDB is fine. I would not recommend using XML as such unless you use an XML Database such as BaseX or eXist but I am not sure what XML will bring you in this case. On the other hand I have been working for quite a while with ObjectDb and the simplicity of use and installation is staggering.

With any of these solutions you should not have too much difficulty creating an installer with your embedded database. The "problem" with the SQL and XML options is that you will need to learn how to query you database (SQL or Xpath...) and you will need to do the hard work of mapping your objects to the persistent representation manually unless you use a mapper such as Hibernate. You don't really want to do that if you are developing a small easily deployable application.

With an object database there is no need to learn SQL (although you can also query your database with OQL if you want to) and crucially, there is no mapping to do.

ObjectDB is a good option and it also is easily embeddable with one file to store the data.

Hope that helps, good luck with your project. Farid

0

精彩评论

暂无评论...
验证码 换一张
取 消