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.
Related
I am using SQLite in my project. Everything works fine in windows, but in OS X I get error as:
Caused by: java.lang.UnsupportedOperationException: Pure Java mode disabled!
at org.sqlite.JDBC.(JDBC.java:34).
What can be the reason for it?
Java has the ability to run as a wrapper around existing C libraries. They refer to these as "native libraries". This is handy for a project like SQLite that already has libraries written in C, you don't have to rewrite everything just for Java.
"Pure Java mode" means it is running only Java code and no native libraries. Usually you do this only if the native library is missing. I don't know why it would be disabled.
Either SQLite JDBC driver is mistakenly not seeing the SQLite library (for which there is an open bug), or you're missing the native/C SQLite library. According to these instructions, you might be able to configure the library manually to use the native library with sqlite.purejava=false.
This question already has answers here:
Java and SQLite [closed]
(9 answers)
Closed 7 years ago.
I need to build a Java application that I will install on a Linux server.
When people will install they just would need to install this application, launch it, and nothing more. But we have some data to save.
I said no to MySQL, because it needs a server.
I said no to XML because there will be really a lot of data to save and manipulate.
So I'm looking at SQLite which is the best I think. Indeed (stop me if i'm wrong), SQLite doesn't need any server? (just install the final application and SQLite works fine in my application?)
Then I checked at http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers and I'm really a little bit confused.
What is the difference between a Wrapper and a Driver?
Plus I see there exists a "pure java implementation": SQLJet is it more or less optimized?
Finally what would you use in my situation?
Another database to consider is H2. It is an embedded database engine completely written in Java so you have the benefit of full unicode (16 bit) character support that Sqlite does not have. Other embedded databases are HSQLDB and Derby.
sqlite doesnt need any requirement on the server ?
Correct. It does not. Neither does H2.
just install the final application and sqlite works fine in my application ?
Correct. As long as you include Sqlite or H2 in your WAR (or unpack it into your jar), it will work fine.
What is the difference between a Wrapper and a Driver ?
Depends on the usage. I think Sqlite is talking about the fact that when you use the JDBC driver for Sqlite, it is actually a wrapping of the Sqlite C native libraries inside the driver. Typically the JDBC driver talks to a remote database.
H2 also is that way with the "driver" actually doing the database operations just that it was written in Java so you don't need the C wrapper.
Plus I see there exists a "pure java implementation" : SQLJet is it more or less optimized?
This is the first I've heard of Sqljet so I'm not sure. The Xerial Sqlite driver is what I've used and it's performance seems to be good.
Finally what would you use in my situation?
I'd use H2 myself for the native Java features.
Yes SQLite doesn't require a server.
One very simple solution for development is using SQLLite by embedding it in your source code, with a little stub data. You can then commit your database to your version control system (i.e. I use github, its super easy to do this) as a single file. This is, obviously, not a good production method, but it is a good way to create a single development version.
A Wrapper is a program which facades another program by allowing you to access its functionality through a different interface. For example, eclipse "wraps" many java programs that we use in everyday development for us in a convenient GUI. Whereas a Driver is a program that is needed to launch an existing application. For example, in a java application, we might have a main class that can be thought of as a Driver for entry point to the application.
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 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.
i am not clear about steps/configuration details about how i can embed mysql in a Java desktop application so that it(application) can be installed on any machine through a single executable file and doing so sets up database and also provides an exe to run the app.Till now i have built my app using netbeans and i have used mysql to set up database.plz guide me further.
MySQL isn't an embedded database - the only JAR related to it is the JDBC driver. It requires a installation process, which might be able to be scripted via Java, but the process will definitely function outside of the Java application you intend it to support. Meaning, you can turn off your Java application but the MySQL service/daemon will still be running.
Only the libmysqld is embeddable.
There are embedded databases - SQLite, Firebird - and embedded databases made in Java - HSQL, Derby/(can't remember what it was called before). I believe SQL Server Compact Edition is embeddable, while SQL Server Express/MSDE is not. I don't know if Oracle has an embeddable version....
I would strongly recommend H2. It is a very fast embedded database written in Java and I've found it easier to use than some of the others mentioned such as HSQL.
Edit:
On the H2 website, you can see a speed comparison of H2 vs Derby, HSQL, MySql, etc...
Here's information on how to backup the database.
While theoritcaly possable it would not be easy. The standard MySql distributions assume you want to set up a general purpose database server with separate from the client applications cominicating via odbc etc.
You may be better looking at the "pure java" options like HSQL or JavaDB which are designed to be embedded in a java application, and need little or no "setup".
Another possibility is Sqlite which only needs a single binary plus the sqljbbc jar file. This is again designed from scratch to be embedded inside an application and requires zero admin apart from allocating a file for the database.
Take a look at http://dev.mysql.com/doc/refman/5.0/en/connector-mxj.html. I do not remember the exact details but I was able to embed MySQL db in desktop application without user needing to install it separately.
The key class is com.mysql.management.MysqldResource.
Here is the example, http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-configuration-java-object.html
The mysql-connector-mxj-gpl-db-files.jar file contains MySQL installation files for all the platforms. If you know which is your target platform, you can strip other platform versions from jar, to reduce download size for end user.
If you want an embedded database with java, then use one written in Java designed to be embedded. I know Apache Derby Can be embedded and apparently H2 too.
How big amount of data dó you need the database to handle?