I saw Java and SQLite, but what ones are made in pure java and are platform independent? Also which would be the best to start with? I have never used sqlite but I assume it is like mysql. Also do any of them come with a nice command line tool for testing queries?
SQLite is getting quite a lot of hype in other language domains, however with Java you have something else available:
HyperSQL (more commonly known as HSQLDB) is pure Java RDBMS which is specialized around running it as part of your application meaning that you can embed it to your software and it just works.
H2 is a complete rewrite of HypersonicSQL (common ancestor for H2 and HyperSQL) and is also fully Java. One nice feature of this one is RDBMS emulation which allows it to function with SQL written specifically for, say, Oracle RDBMS.
There's also the almost mandatory Apache Commons variation too, Apache Derby. As with the other two, Derby is also embeddable and has a small JAR file size footprint.
As for tools, well, that varies a lot. Most of the Hypersonic family products for example are mainly meant for unit testing which means that you can unit test your DB Schemas and actual queries quite easily with (almost) plain Java code.
sqljet, which in contradiction to the name does not have SQL, but can use SQLlite databases.
And updated answer, you may want to try Xerial's Sqlite JDBC driver. While its current version is not pure-java, it packages binaries for major operating systems so that it is mostly portable.
Also sqlite4java also currently packages binaries for major OSes.
Related
i'm planning to start the development of a java desktop application with a database embedded. It will be an application without internet connection and just for that, to insert, update and delete data on the database. It will be a lot of data.
So, i would like to have your opinions, what libraries should i use to incorporate the database in the application to have good performances in the end? Should i use jdbc derby that's already incorporated with neatbeans?
Thanks in advance!
I been using Derby in production for years and it works well. The H2 database also looks good, it's supposed to offer better performance than Derby but I haven't used it in production. Both of these, along with HSQLDB are good choices as they are pure java, all you need to do is bundle the required jar files with your application. Sqlite and Berkely are fine products but not written in Java so I imagine these would be a little more difficult to work with.
You don't need any particular libraries. Each of the above databases should provide a JDBC driver which is the standard way of doing things. You can certainly use an ORM such as Hibernate as mentioned above. This makes some things simpler but if you're just starting out, it might be better to avoid this at first.
Some popular options are:
HSQLDB
BerkleyDB
Sqlite
Derby
Its impossible to say if they will be "fast enough", since its all relative. What is fast enough? How powerful is the host machine? How big is your dataset? Etc etc.
However, I can say I have seen really good performance from HSQLDB, with fairly large dataset (100K records +) on fairly moderate desktop machines. Sqlite I only explored for android, but its pretty impressive on this platform (considering the hardware it is running on).
I think you should do a little proof of concept, and test them out with some simulated data.
If Derby is available, I would use Derby. HSQLDB is another good option. For libraries, I would look at some library for database access. Spring comes to mind. If you have control of the database, I would look at an ORM mapping framework such as Hibernate.
Suppose I created a standalone application in java and distributed it through my website.
What I need to know is what is the ideal Database solution I can use so that all the users can use the application without installing anything extra.
For example, if I use SQL server or MySql database, the downloader will need those installed so that I can dump my database on it. Another solution I see is to use Database file like Microsoft Access .mdb file. But that too will need Microsoft Office installed on the client. XML files are platform independent but anyone can open and change them.
What is the solution used by most of the applications?
H2 is a very potent candidate for your need. We use it as a default RDBMS in all our demo applications and also for db-driven unit testing.
You could use an embedded database. There are hundreds for Java some which use SQL and many which don't. Any database you use, you may want the users to be able to maintain, so users editing the data may be a good thing.
You could consider Derby as it ships with Java.
I would use plain flat files which are CSV formatted unless you have a more specific requirement. e.g. you can load and edit them in excel/spreadsheet editor/text editor.
H2 is the successor of HSQLDB (same developer). It is not only one of the finest embedded DBs for JAVA, it is also free, even for commercial use. It's great with hibernate and comes with with a powerful web-interface (you can start it by running the h2 jar file). Additionally there is the possibility to encrypt you database (AES). We use that feature for getting some security aspects right with some of our projects.
check javadb. it is easy and can be redistributed
Firebird can do this : there is an embedded version.
There is some good java drivers
Using MDB files on Windows doesn't require any additional installation requirements such as Microsoft Office. DAO and ADO have come with the Windows OS since Windows 2000.
I did some research on their site, and after some Google-ing, it looks like there are only drivers for C & C++. Is there an open driver that I can use with SQLLite, or is there a way I can use it with JDBC?
UPDATE
I'm doing development on Linux, but I would like to keep my options open. Native libraries would work, but wouldn't give the cross-platform freedom that I'm used to with Java.
I have used org:xerial:sqlite-jdbc
Example Groovy script:
#Grab(group='org.xerial', module='sqlite-jdbc', version='[3.6.4,)')
sql = groovy.sql.Sql.newInstance("jdbc:sqlite:test.db","org.sqlite.JDBC")
sql.execute("create table students(name, age)")
(note: 3.6.4 is not the latest version)
SQLite JDBC is completely written in Java, so there are no external dependencies.
SQLite is a native library - therefore a platform independent solution is not that simple. The SQLiteJDBC project uses a internally complex but working system for accessing SQLite database platform independent (on most platform with a good speed). As the name implies it can be used via JDBC (see code sample on the main page).
If you only need one specific platform you can also use the SQLite Java wrapper. For windows there are pre-compiled binaries; sources are also available.
There is also SQLJet, which is a pure java impl which is compatible with sqlite.
I've been assigned the task of making our Java web application work with Oracle Database. I am not sure where to start. I was hoping for an experience similar to working with MySQL or PostgreSQL, but no such luck.
The answer to this question will be list of steps for installing and deploying an Oracle Database for development use, basic operations such as starting and stoping, creating and dropping schemas, and perhaps even JDBC connection parameters.
A little bit of background about my project (although ideally the answer to this question will be as general purpose as possible and not be tied to the specifics of my environment):
Java (and Scala) web apps deployed in Tomcat
Hibernate (currently connected to PostgreSQL and MySQL)
Developer workstations run OS X; production deployments are to Red Hat Enterprise Linux
Firstly, don't think about Oracle on OS X. You'll need Linux (or Windows), maybe on a virtual machine/
Then decide whether you'll be using Oracle 10g or 11g. 10g has a free Express Edition which is relatively easy to install on Linux or Windows. However, if you want 11g or bug fixes to 10g or some of the extra options (compression, partitioning...) you'll need a fully licenced version of Oracle. Depends on your load, but you can have one physical machine which is licenced for Oracle, with multiple VMs (one for each developer).
XE has a single database instance that the installer will configure to start up when you start the machine. If you are just using the VM for the database, having the database startup and shutdown with the machine is the easiest way to go.
I have not found a fundamental difference between MySQL and Oracle from a developer's point of view. It's just tables, joins, and SQL. If your database gets enormous or needs insane throughput then yes, it matters a lot. But by then you'll need a real DBA.
Download SQLDeveloper from Oracle. It is free. It will let you perform database maintenance, run SQL statements interactively, etc.
Read up on "connection pooling" and "oracle". There probably some good threads here on SO. You'll want this as it will make your servets run efficiently.
Read up on JNDI database connections. This is simply a way to specify the database connection in your Tomcat configuration so your applications don't have to know anything about the database. You'll be able to move your war files from test to QA to prod with less difficulty.
Hibernate is the trickiest thing of the bunch! Keep it simple! I highly recommend you reverse engineer your model classes from the database and never manually modify them. You can also generate your DAOs (recommended) but you will modify those.
Use standard proper database design as you'll have to play fewer games with Hibernate. For example, always put a numeric PK on each table, and use an Oracle sequence to populate it. Always use FKs when appropriate. Try to normalize your data to a practical extent.
Use Ant or Maven for your builds. Don't do anything by hand.
Use SVN or similar.
That's the biggies for now.
If your database is relatively lightweight and doesn't heavily rely on Oracle-specific features, I would recommend you to use XE for development. In the other case, it might make more sense to dedicate a separate box for running Oracle for development.
As for the basic steps you mentioned, the later versions of oracle come with a rather nice web-frontend(which looks like that) that can handle all of these maintenance tasks. If you would need something better and more responsive, go for Oracle SQL Developer, which is a desktop application somewhat similar to pgAdmin.
Installation is also much easier with the newer versions of Oracle (10g and up), so you should not have any problems with that.
Edit: On memory optimization (if you insist on having an Oracle instance on your workstation and your database is relatively light), check this thread since it provides a multitude of good hints.
Is there a "best" or more popular database for standalone Java app?
I'm currently writing by hand, but I would like to know what is commonly done, if there is something that is commonly done.
update: talking about small app (may grow, but its small for now)
I would suggest using something like SQLite with SQLiteJDBC.
It also sounds like HyperSQL and Derby (which ships with certain Java versions) are popular choices.
Java 6 ships with Derby (renamed JavaDB). It can be used in memory or server mode.
HyperSQL (HSQLDB) is also popular.
For development purposes, I often use the Hypersonic SQL Database (HSQLDB). It's fast and lightweight, and good enough to get started.
For a bigger application, I'd go for Derby, which supports more options.
The main competitors - HyperSQL (HSQLDB), JavaDB (Derby) and SQLite (not java-based) were mentioned.
There are a few other options:
db4o - object database
FirebirdSQL - not java-based.
Jackrabit - a content repository (not RDBMS) supporting embedded mode.
HSQLDB is a well-established option.
JavaDB comes with the development kit
apart all those mentioned here, one can also go for H2 database which is light and can be used in-memory or in server mode.
For a SQL option, you could try MySQL, SQL Server, PostgreSQL, or Oracle. Those seem to be the most popular among Java developers.
If you want something NoSQL, MongoDB is the most popular choice with Java developers based on StackOverflow data from 2022.
You can find more information on the metrics used to make that determination in this article.