I am creating a java jar file that will be used to connect to different databases so this library can be used in many apps and support different databases. i.e. Sqlite3, MySQL, Oracle, etc.
Currently I want to support Android first and want my jar file to connect to Android's builtin Sqlite3 database.
The customer will use are jar file and call the functions in it to create, update, and query the database. So they won't have to use any or Androids API.
However, I am confused about a few things:
1) Can a java jar file create and connect to Android Sqlite3 database without importing the android.database.sqlite.* API. Just using Java's standard API?
2) As all apps are created and ran in their own sandbox on Android, will the database be created and saved to the apps sandbox for security reasons?
Many thanks for any suggestions,
Unfortunately, if you want to create and connect to the built-in android sqlite database you must import android.database.sqlite.*
About the other section of the question, i'm not sure if it's depends on the first one or not but if you use the android api to create it, sure it will be in the application private folder
Can a java jar file create and connect to Android Sqlite3 database without importing the android.database.sqlite.* API. Just using Java's standard API?
sqlite databases are just files. You can read and write files with regular Java APIs.
Though for database use it's better to use the sqlite3 C library for reading and writing the files. Android provides one Java wrapper for it; there are a number of other wrappers as well, including JDBC ones.
As all apps are created and ran in their own sandbox on Android, will the database be created and saved to the apps sandbox for security reasons?
By default the Android database wrapper puts database files in the app's private data directory. It's not accessible to other apps without shared user id or root.
Related
I have a java application which uses MySQL as its database. In order to deliver the project, I need to convert it to an executable with MySQL included. I have tried exe4j but it doesn't allow to include the database. Please advice. The project is done in Netbeans.
Although it's not being actively developed any longer due to low demand, you can have a look at the MySQL-Connector/MXJ package that's meant for "embedding" your MySQL-database into your application - I recon' it still should be able to do the trick.
But to be honest, the most future-proof solution would be to switch out your database with another option, preferably an in memory database such as H2database or SQLite.
So, i've just finished a small java application, with database and stuff...
I used Netbeans and Mysql, now i want to export my project so i can use it anywhere i want;
any computer, even with no Mysql or Java installed!
So, i've tried some programs like Launch4j or something... but the main problem is, even if i make the .exe file, what's gonna happen with the database? it's located in my PC, so if somebody try to use my application, he can't access to the database, so the application won't work...
In other words...What is the solution that i can use to like "Combine" the database with the application, if it is possible? or create the .exe file with the database...
I hope that my problem is clear, and thank you for your answers :)
You can look at MySQL Connector/MXJ to embed your mysql database in your application.
But be aware that this package is no longer under active development:
Due to very low demand, MySQL
has stopped development and support for Connector/MXJ. Source and
binaries for previously released versions will continue to be
available from archives.
An alternative solutation would be using another database like SQLite, H2 or HSQLDB
You can create an executable jar by exporting your project through eclipse. You can do this by following these steps:
Right click on the Project
Export as Jar file
When you were programming in netbeans did you include the database within netbeans? Here is a guide on how to do this.
https://netbeans.org/kb/docs/ide/mysql.html
Also here is a second guide on how to Packaging and Distributing Java Desktop Applications
https://netbeans.org/kb/docs/java/javase-deploy.html
I hope these help.
If not just go over your step you took to build the app.
if you really want to give your users a good experience, I would suggest you implement a embedded database in your application instead.
Look at: http://www.h2database.com/
It's free and open source and I use it heavily myself.
It supports embedded (where it creates flat database files on the computer), in-memory, and server-mode, where you have the possibility of letting multiple-applications share the same database.
It's just a jar file you include in your application, and then the users wont have to install neither MySQL, have access to MySQL on a network drive or need other database software installed.
(depending on your requirements, it might also be a good idea to look into Hibernate, to have some more abstraction between the different RDBMS).
In order to get a database built-in to the application, consider HSQLDB, which is an in-memory database.
http://hsqldb.org/
It can run entirely in the JVM without any external resources.
I have prepared an application that is a small demo of Student information manipulation. I have stored information related to students in a MySQL DB. Now my application is working 100% on my computer. But I want that work everywhere without depending on Database! I mean I just want "WHEREVER MY .JAR FILE GOES, DATABASE SHOULD ALSO GO ALONG WITH THAT INSIDE .JAR FILE "
So anyone who is using my application or trying it, they can realize exact result of this application.
How can I make this possible? Please someone help me.
You will probably need to look at something like HyperSQL, which is a in-memory database (which you will need to populate at application start-up). Or have a look at SQLite, which is an embedded databsase, which you can distribute as a resource in your jar.
This doesn't work. MySQL is a full-blown RDBMS. You would have to install it on every computer if you want application to use it locally. An alternative would be using SQLite.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
SQLite and Java
SQLite seems to be a good fit for your requirements.
I have in my Java app lot off properties that I store in property files ( I read them a ot and write a lot, app is some sort of ide for microprocessors,lot off users can have lot of projects with lot off properties ). I heard something about SQLITE and my question is : Can I use SQLITE and not to use those properties files, but that user doesn't have installed SQLITE server ? Does SQLITE require lot of memory ( if not to put inside installer installation for SQLITE if needed ) ?
There's no such thing as "SQLite server", it's totally embedded fast lightweight DBMS that you can include within your app distribution. It's originally written in C but you can use SQLiteJDBC which includes several native implementations of SQLite as well as 100% pure Java implementation which runs on any platform.
There is no server component for SQLite. It's just a lightweight library that you can use to manipulate a file containing the database.
See this question about libraries for using SQLite in Java: Java and SQLite
If you prefer to use SQL DB then I think you'd be better off using java embedded DB like H2. It's lightweight, fast and easier to embed into a java application (just another jar file).
I am making a desktop application in java and using MSAccess in data base.
I want that if i run the setup of the application the database should be created on client machine because there can be different client using the application and how can i create the setup?
is there any tools available for this free of cost?
please explain me in detail..
thanks
Java 6 (enhanced for desktop application work) comes with a built-in database called JavaDb (formerly IBM's Derby). That will do what you want.
Here's a set of guides and tutorials on how to use it.
I would suggest that when your application first starts, it checks for the presence of the created database, and if it doesn't exist, it builds the database (via the appropriate SQL). I've used this approach before and it works quite well.
I prefer nullsoft. Take a look at Open Source Installers Generators in Java
#pratap: database should be created on client machine..
Add an empty access database to your setup.
Have a look at SQLite, which is used by Mozilla (Firefox stores all bookmarks and history in a database) and several other major applications.
When you say
access in database
do you mean Microsoft Access or access the data in a database.
I would advise against MS Access if that is the case. If not, you could either use the JavaDB or HSQLDB and the use SQL scripts to create the database. As a summary
Package the application in one of the installers (InnoSetup or NSIS are good ones)
When installing, extract all the files in proper folders
Execute the SQL scripts before first running the application to ensure the database is setup, you can do other housekeeping tasks along with this step (refer to installer documentation for after-install steps)
Your application is good to go
In the last distribution of NetBeans I used, there was a wizard to create such application. The application used the Java Persistence API to store the Data.
My option is HSQLDB since it's fast, reliable and easy to use.
In the documentation it's explained how to use the standalone database mode, this is primarily used for unit testing but it fits your case too. The good thing with this is that you just connect to the file based database without any special set up and if the files doesn't exist, they're created.
I would second the posters who recommend JavaDB.
It is absurdly easy to adminster from inside your application. Whats more because everything is native Java you dont get the char->unicode little-endian->big-endien and all the other conversion malarky you normally get when reading SQL into java.
The one tip is that with JavaDB is prepare your SQL statements. Prepared statements get cached and the resulting access program (similar to an access plan but actually a jvm program) is reused, the programs for "executed' statements are not cached.
If you are really set on MSAccess then I would suggest you package an "default.mdb" file with all your required tables defined and your classifcation tables populated. If the user's table does not exist then simply copy over the default .mdb file and open that.
I recommend the H2 database because it is simple, fast, pure Java, and small. See this page for how H2 compares to other Java databases, including those mentioned here in other answers. It has many features Derby/JavaDB and HSQLDB do not.